﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ZG_member.BLL;
using System.Configuration;
using System.IO;
using System.Net;
using ZG_member;
using System.Data.OleDb;
using System.Threading;
using System.Data.SqlClient;
using System.Text.RegularExpressions;

namespace ZG_member
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
            skinEngine1.SkinFile = Application.StartupPath + ConfigurationManager.AppSettings["Skin"];
            this.Opacity = 0;
            top = this.Top;
        }
        int top;

        public static VisualCardPrinter_NPPrinter_New.VisualCardPrinter_NPPrinter vnp;
        int retu;
        public string size = "23";
        public static string num = "1";
        public string deyeshu;
        public static string SelectMemberTJ = "";
        public static string Operator;
        public static DateTime logintime;

        public void CurrYes()
        {
            num = "1";
            string sqlWhere = NewYe();
            memberInfo member = new memberInfo();

            deyeshu = (member.GetList(sqlWhere).Tables[0].Rows.Count / decimal.Parse(size)).ToString("F2");
            int inyeshu = member.GetList(sqlWhere).Tables[0].Rows.Count / Convert.ToInt32(size);
            if (Convert.ToDouble(deyeshu) >= inyeshu)
            {
                inyeshu += 1;
                deyeshu = inyeshu.ToString();
            }
            this.txtAlto.Text = deyeshu;
            this.txtCurr.Text = num;
        }
        public void CurrYe()
        {
            memberInfo member = new memberInfo();
            string sqlWhere = NewYe();
            DataTable dt = member.GetList(sqlWhere).Tables[0];
            int st = dt.Rows.Count;
            if (st <= 0)
            {
                //MessageBox.Show("输入有误！");
                return;
            }
            deyeshu = (st / decimal.Parse(size)).ToString("F2");
            int inyeshu = st / Convert.ToInt32(size);
            if (Convert.ToDouble(deyeshu) > inyeshu)
            {
                inyeshu += 1;
                deyeshu = inyeshu.ToString();
            }
            if (Convert.ToDouble(deyeshu) == inyeshu)
            {
                deyeshu = inyeshu.ToString();
            }
            this.txtAlto.Text = deyeshu;
            this.txtCurr.Text = num;
        }

        public string GetcardType()
        {
            //StringBuilder sb = new StringBuilder();
            //string sign = "";
            //for (int i = 0; i < clbxMemberLevel.Items.Count; i++)
            //{
            //    if (clbxMemberLevel.GetItemChecked(i))
            //    {
            //        sb.Append(sign);
            //        sb.Append("'");
            //        sb.Append(clbxMemberLevel.Items[i].ToString());
            //        sb.Append("'");
            //        sign = ",";
            //    }
            //}
            //if (sb.ToString() == "")
            //{
            //    sb.Append("null");
            //}
            //string abc = sb.ToString();
            string sst = "";
            //if (SelectMemberTJ.Trim() != "")
            //{
            //    sst = "" + SelectMemberTJ + " and cardType in (select id from consumeSolution where solutionName in (" + sb.ToString() + "))order by id ";
            //}
            //else
            //{
            //    sst = "cardType in (select id from consumeSolution where solutionName in (" + sb.ToString() + "))order by id";
            //}
            if (SelectMemberTJ.Trim() != "")
            {
                sst += "" + SelectMemberTJ + " and ";
            }
            
            for (int i = 0; i < clbxMemberLevel.CheckedItems.Count; i++)
            {
                if (clbxMemberLevel.CheckedItems[i].ToString() == "有卡")
                {
                    sst += "memberCardId !='' or  ";
                }
                if (clbxMemberLevel.CheckedItems[i].ToString() == "无卡")
                {
                    sst += "memberCardId ='' or ";
                }
            }
            if (clbxMemberLevel.CheckedItems.Count != 0)
            {
                sst = sst.Remove(sst.LastIndexOf("or"), 2);
            }
            else if(sst!="")
            {
                sst = sst.Remove(sst.LastIndexOf("and"), 3);
            }
            memberInfobindDataGridView(sst, "");
            return sst;

        }
        public string NewYe()
        {
            //StringBuilder sb = new StringBuilder();
            //string sign = "";
            //for (int i = 0; i < clbxMemberLevel.Items.Count; i++)
            //{
            //    if (clbxMemberLevel.GetItemChecked(i))
            //    {
            //        sb.Append(sign);
            //        sb.Append("'");
            //        sb.Append(clbxMemberLevel.Items[i].ToString());
            //        sb.Append("'");
            //        sign = ",";
            //    }
            //}
            //if (sb.ToString() == "")
            //{
            //    sb.Append("null");
            //}
            //string abc = sb.ToString();
            string sst = "";
            //if (SelectMemberTJ != "")
            //{
            //    sst = "" + SelectMemberTJ + " and cardType in (select id from consumeSolution where solutionName in (" + sb.ToString() + ")) order by id";
            //}
            //else
            //{
            //    sst = "cardType in (select id from consumeSolution where solutionName in (" + sb.ToString() + ")) order by id";
            //}
            if (SelectMemberTJ.Trim() != "")
            {
                sst += "" + SelectMemberTJ + " and ";
            }

            for (int i = 0; i < clbxMemberLevel.CheckedItems.Count; i++)
            {
                if (clbxMemberLevel.CheckedItems[i].ToString() == "有卡")
                {
                    sst += "memberCardId !='' or  ";
                }
                if (clbxMemberLevel.CheckedItems[i].ToString() == "无卡")
                {
                    sst += "memberCardId ='' or ";
                }
            }
            
            if (clbxMemberLevel.CheckedItems.Count != 0)
            {
                sst = sst.Remove(sst.LastIndexOf("or"), 2);
            }
            else if (sst != "")
            {
                sst = sst.Remove(sst.LastIndexOf("and"), 3);
            }
            if (clbxMemberLevel.CheckedItems.Count == 0)
            {
                sst += " memberCardId !='' and memberCardId =''  ";
            }
            memberInfobindDataGridView(sst, "");
            return sst;
        }
        public void shifouxianshi(string username)
        {
            BLL.operatorInfo oif = new BLL.operatorInfo();
            string where = " username = '" + username + "' ";
            Model.operatorInfo omodle = oif.GetModelList(where)[0];
            //if (omodle.roleId == 13)
            //{
                memberInfobindDataGridView();
            //}
        }
        private void MainForm_Load(object sender, EventArgs e)
        {
            this.helpProvider1.HelpNamespace = Application.StartupPath + @"\帮助文档(管理端).chm";
            helpProvider1.SetHelpString(this, "Enter an age that is less than 65.");
            helpProvider1.SetHelpString(this, "Enter a 5 digit post code.");
            bindClbxMemberLevel();


            shifouxianshi(MainForm.Operator);
            //memberInfobindDataGridView();

            //************************************************
            //xianshixiangqing();
            ////dgvxiaofeixiangqing.DataSource = null;
            //Application.DoEvents();
            ////************************************************
            //xianshixiangqing();
            //memberInfo mem = new memberInfo();
            //DataTable memTB= mem.GetList("").Tables[0];
            CurrYe();
            this.timer4.Start();

            int duankou = Convert.ToInt32(ConfigurationManager.AppSettings["ComPort"]);
            int botelv = Convert.ToInt32(ConfigurationManager.AppSettings["Bandrate"]);

            byte[] printer = System.Text.Encoding.Default.GetBytes(ConfigurationManager.AppSettings["printer"]);
            int x = Convert.ToInt32(ConfigurationManager.AppSettings["X"].ToString());
            int y = Convert.ToInt32(ConfigurationManager.AppSettings["Y"]);
            int direction = Convert.ToInt32(ConfigurationManager.AppSettings["direction"]);
            byte[] fontname = System.Text.Encoding.Default.GetBytes(ConfigurationManager.AppSettings["Font"]);
            int fontsize = int.Parse(ConfigurationManager.AppSettings["Font-Size"]);

            //VN = new VisualCardPrinter_NPPrinter_New.VisualCardPrinter_NPPrinter(
            //     duankou, botelv, printer, x, y, direction, fontname, fontsize, ref retu);
            //bool Port = VisualCardPrinter_NPPrinter.VisualCardPrinter_NPPrinter.Port;

            vnp = new VisualCardPrinter_NPPrinter_New.VisualCardPrinter_NPPrinter(duankou, botelv, printer, x, y, direction, fontname, fontsize, ref retu);
            VisualCardPrinter_NPPrinter_New.RCP.串口号 = duankou;
            VisualCardPrinter_NPPrinter_New.RCP.波特率 = botelv;

            dgvMemberInfo.AllowUserToAddRows = false;
            UserInfo();
            //systemnode();

            tvwMenu.ExpandAll();


            tvwMenu.SelectedNode = tvwMenu.Nodes[0];

            // this.timer1.Start();
            //=======================================================

            //select name from sysobjects where xtype='U';
            //StreamReader writer = new StreamReader(@"E:\李杰\开发资料\公司项目开发\国金\2013年4月27日101811\ZG_GJ\ZG_member\bin\Debug\Sqlupdate.txt");

            //string a = writer.ReadLine();
            //MessageBox.Show("Test:" + a);

            //=======================================================
            //if (Port == false)
            //{
            //    MessageBox.Show("打印机端口打开失败，请确认打印机线路正常。");
            //}
            StreamReader writer = new StreamReader(Application.StartupPath + "\\zhinengjuece.txt");

            string a = writer.ReadLine();
            writer.Close();

            if (a == "1" ? true : false)
            {
                Intelligencerole il = new Intelligencerole();
                il.Owner = this;
                il.Show();
            }



            //try
            //{
            //    HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://sdk2.entinfo.cn:8060/webservice.asmx");
            //    HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
            //    if (resp.StatusCode == HttpStatusCode.OK)
            //    {
            //        string sql = ConfigurationManager.AppSettings["fuwuqi"];
            //        ConfigurationManager.AppSettings["ConnectionString"] = sql;
            //        ConfigurationManager.AppSettings["details"] = "1";


            //        resp.Close();
            //    }
            //    else
            //    {
            //        System.Windows.Forms.MessageBox.Show("由于您的电脑未联网！本次将使用本地数据库！");
            //    }
            //}
            //catch (WebException webex)
            //{
            //    string sql = ConfigurationManager.AppSettings["bendi"];
            //    ConfigurationManager.AppSettings["ConnectionString"] = sql;
            //    ConfigurationManager.AppSettings["details"] = "0";
            //    System.Windows.Forms.MessageBox.Show("由于您的电脑未联网！本次将使用本地数据库！");

            //}
            //try
            //{
            //    HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://sdk2.entinfo.cn:8060/webservice.asmx");
            //    HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
            //    if (resp.StatusCode == HttpStatusCode.OK)
            //    {
            //        resp.Close();
            //        this.timer5.Start();
            //    }
            //    else
            //    {

            //    }
            //}
            //catch (WebException webex)
            //{

            //    MessageBox.Show("由于您的计算机未连网！将无法接受短信！");

            //}
            //brithdayFromBill b = new brithdayFromBill();
            //b.TopMost = true;
            //b.Show();
            //ExpiredInquiry ex = new ExpiredInquiry();
            //ex.TopMost = true;
            //ex.Show();
        }




        public void bindClbxMemberLevel()
        {
            //clbxMemberLevel.Items.Clear();
            //consumeSolution solution = new consumeSolution();
            //DataTable dt = solution.GetList("").Tables[0];
            //for (int i = 0; i < dt.Rows.Count; i++)
            //{
            //    clbxMemberLevel.Items.Add(dt.Rows[i]["solutionName"].ToString(), true);
            //}
            clbxMemberLevel.Items.Add("有卡", true);
            clbxMemberLevel.Items.Add("无卡", true);

            clbxMemberLevel.Update();
        }

        /// <summary>
        /// 系统日志信息
        /// </summary>
        /// 
        public DateTime Date;
        public void systemnode()
        {
            usersystemnode node = new usersystemnode();
            Model.usersystemnode nodeModel = new Model.usersystemnode();
            nodeModel.username = username;
            Date = DateTime.Now;
            nodeModel.loginTime = Date;
            int row = node.Add(nodeModel);
            if (row <= 0)
            {
                MessageBox.Show("系统出现问题！");
                Application.Exit();
            }
        }


        /// <summary>
        /// 用户信息
        /// </summary>
        public string username;
        private string roleInfo1;
        public void UserInfo()
        {
            //StreamReader sr = new StreamReader("UserInfo.ini", Encoding.GetEncoding("gb2312"));
            //if (sr.Peek() >= 0)
            //{
            //    username = sr.ReadLine();
            //}
            //else
            //{

            //}
            //sr.Close();
            //权限设置
            tvwMenu.Nodes[0].Nodes.Clear();
            tvwMenu.Nodes[1].Nodes.Clear();
            tvwMenu.Nodes[2].Nodes.Clear();
            tvwMenu.Nodes[3].Nodes.Clear();
            tvwMenu.Nodes[4].Nodes.Clear();
            try
            {
                operatorInfo info = new operatorInfo();
                Model.operatorInfo infoModel = new Model.operatorInfo();
                infoModel = info.GetModelList("username='" + MainForm.Operator + "'")[0];
                roleInfo role = new roleInfo();
                Model.roleInfo roleModel = new Model.roleInfo();
                roleModel = role.GetModelList("id='" + infoModel.roleId + "'")[0];
                operatorName.Text = "当前操作员：" + MainForm.Operator + "  " + roleModel.roleName;
                roleInfo1 = roleModel.roleInfo1;

                shifouxianshi(MainForm.Operator);
                int i = 0;
                if (roleInfo1[i] == '1')
                {
                    tvwMenu.Nodes[0].Nodes.Add("会员消费");
                    //tvwMenu.Nodes[0].Nodes.RemoveByKey("会员消费");

                }
                if (roleInfo1[++i] == '1')
                {
                    tvwMenu.Nodes[0].Nodes.Add("会员充值");

                    //tvwMenu.Nodes[0].Nodes.RemoveByKey("会员消费");

                }

                //if (roleInfo1[++i] == '1')
                //{
                //    tvwMenu.Nodes[0].Nodes.Add("会员充值");
                //    //tvwMenu.Nodes[0].Nodes.RemoveByKey("会员充值");
                //}
                if (roleInfo1[++i] == '1')
                {
                    tvwMenu.Nodes[0].Nodes.Add("添加会员");
                    //tvwMenu.Nodes[0].Nodes.RemoveByKey("添加会员");
                }
                if (roleInfo1[++i] == '1')
                {
                    tvwMenu.Nodes[0].Nodes.Add("修改会员");
                    //tvwMenu.Nodes[0].Nodes.RemoveByKey("修改会员");
                }
                if (roleInfo1[++i] == '1')
                {
                    tvwMenu.Nodes[0].Nodes.Add("删除会员");
                    //tvwMenu.Nodes[0].Nodes.RemoveByKey("删除会员");
                }



                if (roleInfo1[++i] == '1')
                {
                    tvwMenu.Nodes[0].Nodes.Add("挂失办理");
                    //tvwMenu.Nodes[0].Nodes.RemoveByKey("挂失办理");
                }
                //if (roleInfo1[++i] == '1')
                //{
                //    //tvwMenu.Nodes[0].Nodes.Add("积分换礼");
                //    //tvwMenu.Nodes[0].Nodes.RemoveByKey("积分换礼");
                //}



                if (roleInfo1[++i] == '1')
                {

                    tvwMenu.Nodes[0].Nodes.Add("查找会员");
                    //tvwMenu.Nodes[0].Nodes.RemoveByKey("查找会员");
                }
                if (roleInfo1[++i] == '1')
                {
                    tvwMenu.Nodes[0].Nodes.Add("修改卡密码");
                    //tvwMenu.Nodes[0].Nodes.RemoveByKey("修改卡密码");
                }

                if (roleInfo1[++i] == '1')
                {
                    tvwMenu.SelectedNode = tvwMenu.Nodes[0];
                    tvwMenu.Nodes[0].Nodes.Add("更换用户");
                    //tvwMenu.Nodes[0].Nodes.RemoveByKey("更换用户");
                }
                if (roleInfo1[++i] == '1')
                {
                    tvwMenu.Nodes[0].Nodes.Add("系统锁屏");
                    //tvwMenu.Nodes[0].Nodes.RemoveByKey("系统锁屏");
                }

                if (roleInfo1[++i] == '1')
                {
                    tvwMenu.Nodes[0].Nodes.Add("卡金提醒");
                    //tvwMenu.Nodes[0].Nodes.RemoveByKey("卡金提醒");
                }
                if (roleInfo1[++i] == '1')
                {
                    tvwMenu.Nodes[0].Nodes.Add("生日提醒");
                    //tvwMenu.Nodes[0].Nodes.RemoveByKey("生日提醒");
                }
                
                //if (roleInfo1[++i] == '1')
                //{
                //    //tvwMenu.Nodes[0].Nodes.Add("群发短信");
                //    //tvwMenu.Nodes[1].Nodes.RemoveByKey("角色管理");
                //}
                if (roleInfo1[++i] == '1')
                {
                    tvwMenu.Nodes[0].Nodes.Add("群发邮件");
                    //tvwMenu.Nodes[1].Nodes.RemoveByKey("角色管理");
                }
                //if (roleInfo1[++i] == '1')
                //{
                //    tvwMenu.Nodes[0].Nodes.Add("批量会员导入");
                //    //tvwMenu.Nodes[1].Nodes.RemoveByKey("角色管理");
                //}
                if (roleInfo1[++i] == '1')
                {
                    tvwMenu.Nodes[0].Nodes.Add("批量会员导出");
                    //tvwMenu.Nodes[1].Nodes.RemoveByKey("角色管理");
                }
                if (roleInfo1[++i] == '1')
                {
                    tvwMenu.Nodes[1].Nodes.Add("统计区块");
                }
                if (roleInfo1[++i] == '1')
                {
                    tvwMenu.Nodes[1].Nodes.Add("课程阶段");
                }
                if (roleInfo1[++i] == '1')
                {
                    tvwMenu.Nodes[1].Nodes.Add("客户预约");
                }
                if (roleInfo1[++i] == '1')
                {
                    tvwMenu.Nodes[1].Nodes.Add("讲话设置");
                }

                if (roleInfo1[++i] == '1')
                {
                    tvwMenu.Nodes[1].Nodes.Add("添加用户");
                }

                if (roleInfo1[++i] == '1')
                {
                    tvwMenu.Nodes[1].Nodes.Add("生日提醒设置");
                    //tvwMenu.Nodes[1].Nodes.RemoveByKey("生日提醒设置");
                }
                if (roleInfo1[++i] == '1')
                {
                    tvwMenu.Nodes[1].Nodes.Add("会员等级");
                    //tvwMenu.Nodes[1].Nodes.RemoveByKey("会员等级");
                }
                if (roleInfo1[++i] == '1')
                {
                    tvwMenu.Nodes[1].Nodes.Add("卡面设计");
                    //tvwMenu.Nodes[1].Nodes.RemoveByKey("卡面设计");
                }
                if (roleInfo1[++i] == '1')
                {
                    tvwMenu.Nodes[1].Nodes.Add("商品设置");
                    //tvwMenu.Nodes[1].Nodes.RemoveByKey("商品设置");
                }

                //if (roleInfo1[++i] == '1')
                //{
                //    //tvwMenu.Nodes[1].Nodes.Add("添加礼品");
                //    //tvwMenu.Nodes[1].Nodes.RemoveByKey("添加礼品");
                //}
                //if (roleInfo1[++i] == '1')
                //{
                //    //tvwMenu.Nodes[1].Nodes.Add("礼品设置");
                //    //tvwMenu.Nodes[1].Nodes.RemoveByKey("礼品设置");
                //}
                if (roleInfo1[++i] == '1')
                {
                    tvwMenu.Nodes[1].Nodes.Add("角色管理");
                    //tvwMenu.Nodes[1].Nodes.RemoveByKey("礼品设置");
                }

                if (roleInfo1[++i] == '1')
                {
                    tvwMenu.Nodes[1].Nodes.Add("销售管理");
                    //tvwMenu.Nodes[1].Nodes.RemoveByKey("礼品设置");
                }

                if (roleInfo1[++i] == '1')
                {
                    tvwMenu.Nodes[1].Nodes.Add("施工管理");
                    //tvwMenu.Nodes[1].Nodes.RemoveByKey("礼品设置");
                }

                if (roleInfo1[++i] == '1')
                {
                    tvwMenu.Nodes[2].Nodes.Add("操作员管理");
                    //tvwMenu.Nodes[2].Nodes.RemoveByKey("操作员管理");
                }
                if (roleInfo1[++i] == '1')
                {
                    tvwMenu.Nodes[2].Nodes.Add("智能决策管理");
                    //tvwMenu.Nodes[3].Nodes.RemoveByKey("充值查询");
                }


                if (roleInfo1[++i] == '1')
                {
                    tvwMenu.Nodes[3].Nodes.Add("客户查询");
                    //tvwMenu.Nodes[3].Nodes.RemoveByKey("客户查询");
                }
                if (roleInfo1[++i] == '1')
                {
                    tvwMenu.Nodes[3].Nodes.Add("用户贡献查询");
                    //tvwMenu.Nodes[3].Nodes.RemoveByKey("用户贡献查询");
                }
                if (roleInfo1[++i] == '1')
                {
                    tvwMenu.Nodes[3].Nodes.Add("商品查询");
                    //tvwMenu.Nodes[3].Nodes.RemoveByKey("商品查询");
                }
                //if (roleInfo1[++i] == '1')
                //{
                //    tvwMenu.Nodes[3].Nodes.Add("充值查询");
                //    //tvwMenu.Nodes[3].Nodes.RemoveByKey("充值查询");
                //}

                if (roleInfo1[++i] == '1')
                {
                    tvwMenu.Nodes[3].Nodes.Add("会员统计");
                    //tvwMenu.Nodes[3].Nodes.RemoveByKey("充值查询");
                }
                if (roleInfo1[++i] == '1')
                {
                    tvwMenu.Nodes[3].Nodes.Add("年龄分析");
                    //tvwMenu.Nodes[3].Nodes.RemoveByKey("充值查询");
                }

                //AgeanalyseChart
                if (roleInfo1[++i] == '1')
                {
                    tvwMenu.Nodes[3].Nodes.Add("商品饼图查询");
                    //tvwMenu.Nodes[3].Nodes.RemoveByKey("充值查询");
                }
                //if (roleInfo1[++i] == '1')
                //{
                //    //tvwMenu.Nodes[3].Nodes.Add("回信统计");
                //    //tvwMenu.Nodes[3].Nodes.RemoveByKey("充值查询");
                //}
                if (roleInfo1[++i] == '1')
                {
                    tvwMenu.Nodes[4].Nodes.Add("会员行为记录");
                    //tvwMenu.Nodes[2].Nodes.RemoveByKey("系统日志");
                }
                if (roleInfo1[++i] == '1')
                {
                    tvwMenu.Nodes[4].Nodes.Add("到期查询");
                    //tvwMenu.Nodes[2].Nodes.RemoveByKey("系统日志");
                }
                if (roleInfo1[++i] == '1')
                {
                    tvwMenu.Nodes[4].Nodes.Add("系统日志");
                    //tvwMenu.Nodes[2].Nodes.RemoveByKey("系统日志");
                }
                //if (roleInfo1[++i] == '1')
                //{
                //    //tvwMenu.Nodes[4].Nodes.Add("无卡用户流水");
                //    //tvwMenu.Nodes[2].Nodes.RemoveByKey("系统日志");
                //}

                //if (roleInfo1[++i] == '1')
                //{
                //    //tvwMenu.Nodes[4].Nodes.Add("消费流水");
                //    //tvwMenu.Nodes[4].Nodes.RemoveByKey("消费流水");
                //}
                if (roleInfo1[++i] == '1')
                {
                    tvwMenu.Nodes[4].Nodes.Add("收入明细查询");
                    //tvwMenu.Nodes[4].Nodes.RemoveByKey("收入明细");
                }

                //if (roleInfo1[++i] == '1')
                //{
                //    //tvwMenu.Nodes[4].Nodes.Add("礼品兑换统计");
                //    //tvwMenu.Nodes[4].Nodes.RemoveByKey("礼品兑换统计");
                //}
                if (roleInfo1[++i] == '1')
                {
                    tvwMenu.Nodes[4].Nodes.Add("折扣查询");
                    //tvwMenu.Nodes[4].Nodes.RemoveByKey("收入明细");
                }
                if (roleInfo1[++i] == '1')
                {
                    tvwMenu.Nodes[4].Nodes.Add("商品流水");
                    //tvwMenu.Nodes[1].Nodes.RemoveByKey("商品流水");
                }


                tvwMenu.Update();
            }
            catch { }
        }











        /// <summary>
        /// 修改信息DataGridView
        /// </summary>
        public void memberInfobindDataGridView()
        {
            memberInfobindDataGridView("", "");
        }

        /// <summary>
        /// 修改信息DataGridView
        /// </summary>
        public void memberInfobindDataGridView(string strWhere, string shaixuan)
        {

            dgvMemberInfo.Columns["Balance"].DefaultCellStyle.Format = "N2";
            dgvMemberInfo.Columns["consume"].DefaultCellStyle.Format = "N2";
            try
            {
                memberInfo memInfo = new memberInfo();
                DataTable dt = memInfo.Mains(size, num, strWhere, shaixuan).Tables[0];

                dgvMemberInfo.DataSource = dt;
                consumeSolution consume = new consumeSolution();
                Model.consumeSolution consumeMod = new Model.consumeSolution();
                Areas area = new Areas();
                ZG_member.Model.Areas areMode = new ZG_member.Model.Areas();
                taocanjiluBLL taocan = new taocanjiluBLL();
                Model.taocanjilu taocanMode = new Model.taocanjilu();
                string[] list = new string[] { };

                foreach (DataGridViewRow dgvr in dgvMemberInfo.Rows)
                {
                    // Shengyukecheng
                    //  GetModelFormemberCardId()
                    if (dgvr.Cells["membercardId"].Value.ToString().Trim() == "")
                    {
                        dgvr.DefaultCellStyle.BackColor = Color.Yellow;
                    }
                    string cardType1 = dgvr.Cells["cardType1"].Value.ToString();
                    if (cardType1 != "")
                    {
                        int ID = int.Parse(dgvr.Cells["cardType1"].Value.ToString());
                        consumeMod = consume.GetModelList("id='" + ID + "'")[0];
                        dgvr.Cells["NewcardType"].Value = consumeMod.solutionName;
                    }
                    if (dgvr.Cells["AreasID"].Value != "")
                    {
                        int id = int.Parse(dgvr.Cells["AreasID"].Value.ToString());
                        areMode = area.getModel(id);
                        dgvr.Cells["AreaName"].Value = areMode.AreaName;
                    }
                    //if (dgvr.Cells["Shengyukecheng"].Value != "")
                    //{
                    //    string memberId = dgvr.Cells["memberId"].Value.ToString();
                    //    taocanMode = taocan.GetModelFormemberCardId(memberId);
                    //    int shengyukecheng = 0;
                    //    if (taocanMode == null)
                    //    {
                    //        dgvr.Cells["Shengyukecheng"].Value = 0;
                    //        continue;
                    //    }
                    //    if (taocanMode.Xiangqing!=null)
                    //    {
                    //        list = taocanMode.Xiangqing.Split('|');
                    //        for (int i = 0; i < list.Count()-1; i++)
                    //        {
                    //           shengyukecheng=shengyukecheng+ Convert.ToInt32(list[i].Substring(list[i].IndexOf(',') + 1));
                    //        }
                    //        dgvr.Cells["Shengyukecheng"].Value = shengyukecheng;
                    //    }
                    //    else
                    //    {
                    //        dgvr.Cells["Shengyukecheng"].Value = 0;
                    //    }
                    //}

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

        }
        public bool Down;
        private void publishCardpic_Click(object sender, EventArgs e)
        {
            Down = true;
            publishCardForm pcard = new publishCardForm(this, "0", vnp);
            pcard.ShowDialog();
        }
        /// <summary>
        /// 给publishCardForm页面传值
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        //private void picUptMemberInfo_Click(object sender, EventArgs e)
        //{
        //    Down = false;
        //    publishCardForm pcard = new publishCardForm(this,0,VN);
        //    if (dgvMemberInfo.CurrentRow.Cells["memberId"].Value != null)
        //    {
        //        pcard.txtMenberId.Text = dgvMemberInfo.CurrentRow.Cells["memberId"].Value.ToString();
        //    }

        //    if (dgvMemberInfo.CurrentRow.Cells["memberName"].Value != null)
        //    {
        //        pcard.txtMenberName.Text = dgvMemberInfo.CurrentRow.Cells["memberName"].Value.ToString();
        //    }
        //    if (dgvMemberInfo.CurrentRow.Cells["sexName"].Value != null)
        //    {
        //        pcard.cbxsex.Text = dgvMemberInfo.CurrentRow.Cells["sexName"].Value.ToString();
        //    }
        //    if (dgvMemberInfo.CurrentRow.Cells["Email"].Value != null)
        //    {
        //        pcard.txtEmail.Text = dgvMemberInfo.CurrentRow.Cells["Email"].Value.ToString();
        //    }
        //    if (dgvMemberInfo.CurrentRow.Cells["mobile1"].Value != null)
        //    {
        //        pcard.txtMobile.Text = dgvMemberInfo.CurrentRow.Cells["mobile1"].Value.ToString();
        //    }
        //    if (dgvMemberInfo.CurrentRow.Cells["Tel"].Value != null)
        //    {
        //        pcard.txtTel.Text = dgvMemberInfo.CurrentRow.Cells["Tel"].Value.ToString();
        //    }
        //    if (dgvMemberInfo.CurrentRow.Cells["Birthday"].Value != null)
        //    {
        //        pcard.dateBirthday.Text = dgvMemberInfo.CurrentRow.Cells["Birthday"].Value.ToString();
        //    }
        //    if (dgvMemberInfo.CurrentRow.Cells["IDNumber"].Value != null)
        //    {
        //        pcard.txtIDNumber.Text = dgvMemberInfo.CurrentRow.Cells["IDNumber"].Value.ToString();
        //    }
        //    if (dgvMemberInfo.CurrentRow.Cells["NewcardType"].Value != null)
        //    {
        //        pcard.cmbType.Text = dgvMemberInfo.CurrentRow.Cells["NewcardType"].Value.ToString();
        //    }
        //    if (dgvMemberInfo.CurrentRow.Cells["point"].Value != null)
        //    {
        //        pcard.txtPoint.Text = dgvMemberInfo.CurrentRow.Cells["point"].Value.ToString();
        //    }
        //    if (dgvMemberInfo.CurrentRow.Cells["Newstatus"].Value != null)
        //    {
        //        pcard.cbxStatus.SelectedText = dgvMemberInfo.CurrentRow.Cells["Newstatus"].Value.ToString();
        //    }
        //    if (dgvMemberInfo.CurrentRow.Cells["CreateDate1"].Value != null)
        //    {
        //        pcard.dateCreateDate.Text = dgvMemberInfo.CurrentRow.Cells["CreateDate1"].Value.ToString();
        //    }
        //    if (dgvMemberInfo.CurrentRow.Cells["ExpiresDate"].Value != null)
        //    {
        //        pcard.dateExpiresDate.Text = dgvMemberInfo.CurrentRow.Cells["ExpiresDate"].Value.ToString();
        //    }
        //    if (dgvMemberInfo.CurrentRow.Cells["Balance"].Value != null)
        //    {
        //        pcard.txtBalance.Text = dgvMemberInfo.CurrentRow.Cells["Balance"].Value.ToString();
        //    }

        //    if (dgvMemberInfo.CurrentRow.Cells["Memo"].Value != null)
        //    {
        //        pcard.txtMemo.Text = dgvMemberInfo.CurrentRow.Cells["Memo"].Value.ToString();
        //    }
        //    pcard.ShowDialog();


        //}
        /// <summary>
        ///  删除会员信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void picDelMemberInfo_Click(object sender, EventArgs e)
        {
            Decimal balance = Decimal.Parse(dgvMemberInfo.CurrentRow.Cells["Balance"].Value.ToString());
            int ID = int.Parse(dgvMemberInfo.CurrentRow.Cells["id"].Value.ToString());
            if (dgvMemberInfo.CurrentRow.Cells["id"].Value != null)
            {
                    DialogResult dr = MessageBox.Show("卡内余额为:"+balance+",是否删除？", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
                    if (dr == DialogResult.OK)
                    {
                        memberInfo menber = new memberInfo();
                        ZG_member.Model.memberInfo menberMode=new ZG_member.Model.memberInfo();
                        ZG_member.BLL.SalesStaffList sales = new ZG_member.BLL.SalesStaffList();
                        ZG_member.Model.SalesStaffList salesMode = new ZG_member.Model.SalesStaffList();
                        ZG_member.BLL.SalesWasteBook salesWaste = new ZG_member.BLL.SalesWasteBook();
                        ZG_member.Model.SalesWasteBook salesWasteMode = new ZG_member.Model.SalesWasteBook();
                        ZG_member.BLL.wasteBook waste = new ZG_member.BLL.wasteBook();
                        ZG_member.Model.wasteBook wasteMode = new ZG_member.Model.wasteBook();
                        menberMode = menber.GetModel(ID);
                        //销售人员减钱
                        salesMode= sales.GetModel(menberMode.OpenTeacher);
                        salesMode.Money =Convert.ToDouble(balance * -1);
                        sales.Update(salesMode);
                        //销售流水添加记录
                        salesWasteMode.SalesPersonId = menberMode.OpenTeacher;
                        salesWasteMode.Dates =Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd"));
                        salesWasteMode.Source = "充值";
                        salesWasteMode.money = Convert.ToDouble(balance * -1);
                        salesWasteMode.memberId = menberMode.memberId;
                        salesWaste.add(salesWasteMode);
                        //消费流水增加记录
                        wasteMode.memberCardId = menberMode.memberId;
                        wasteMode.consumeTimes ="1";
                        wasteMode.operatorId = MainForm.Operator;
                        wasteMode.consumeType = menberMode.cardType;
                        wasteMode.cardPayMoney = 0;
                        wasteMode.cashPayMoney = 0;
                        wasteMode.consumeMoney = balance * -1;
                        wasteMode.consumeIntegral = 0;
                        //wastebookModel.totalIntegral = int.Parse(this.txtjifenzhifu.Text) + (int)decimal.Parse(Integral);
                        wasteMode.totalIntegral = 0;
                        wasteMode.exchangeIntegral = 0;
                        wasteMode.savingMoney = balance * -1;
                        wasteMode.refundmentIntegral = 0;
                        wasteMode.refundmentMoney = balance;
                        //wastebookModel.cardBalance = decimal.Parse(this.TxtBalance.Text) + decimal.Parse(TxtCardPay.Text);
                        wasteMode.cardBalance = 0;
                        wasteMode.date = DateTime.Parse(DateTime.Now.ToString());
                        wasteMode.details = "退款记录";
                        wasteMode.terminalId = "0";
                        wasteMode.Discount = 0;
                        wasteMode.Jiedairen = "";
                        waste.Add(wasteMode);

                        if (menber.Delete(ID))
                        {


                            MainForm_Load(sender, e);
                        }
                    }               
            }
        }


        private void picSctMemberInfo_Click(object sender, EventArgs e)
        {
            MenberSelect select = new MenberSelect(this);
            select.ShowDialog();
        }


        private void pcbchangepassword_Click(object sender, EventArgs e)
        {

            changepassword change = new changepassword();
            if (dgvMemberInfo.Rows.Count > 0)
            {
                change.txtCardId.Text = dgvMemberInfo.CurrentRow.Cells["membercardId"].Value.ToString();
                change.txtmemberName.Text = dgvMemberInfo.CurrentRow.Cells["memberName"].Value.ToString();
            }
            change.ShowDialog();

        }

        private void pcbroleinfo_Click(object sender, EventArgs e)
        {
            RollInfo info = new RollInfo();
            info.ShowDialog();
        }

        private void pcboperatorInfo_Click(object sender, EventArgs e)
        {
            OperatorInfo info = new OperatorInfo();
            info.ShowDialog();
        }



      

        private void pcbbasicsettings_Click(object sender, EventArgs e)
        {
            ConsumeSolutionForm solutionForm = new ConsumeSolutionForm();
            solutionForm.ShowDialog();
        }

        private void picCardTemplate_Click(object sender, EventArgs e)
        {
            CardTemplateDesignMainForm cardTemp = new CardTemplateDesignMainForm();
            cardTemp.ShowDialog();
        }

        private void picProduce_Click(object sender, EventArgs e)
        {
            ProduceForm Form = new ProduceForm(this);
            Form.ShowDialog();
        }

        private void pcbrecovery_Click(object sender, EventArgs e)
        {
            ReStoreForm Form = new ReStoreForm();
            Form.ShowDialog();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            DialogResult dt = MessageBox.Show("您确定要退出系统吗？", "会员管理系统", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
            if (dt == DialogResult.Yes)
            {
                //usersystemnode node = new usersystemnode();
                //StringBuilder sbd = new StringBuilder();
                //sbd.Append("username='" + MainForm.Operator + "'");
                //sbd.Append(" and leaveTime is null");
                //DataTable dtt = node.GetList(sbd.ToString()).Tables[0];
                //if (dtt.Rows.Count > 0)
                //{
                //    Model.usersystemnode nodeModel = node.GetModelList(sbd.ToString())[0];
                //    nodeModel.username = MainForm.Operator;
                //    nodeModel.leaveTime = DateTime.Now;
                //    if (node.Update(nodeModel))
                //    {
                //        this.Close();
                //    }
                //    else
                //    {
                //        MessageBox.Show("系统出现日志错误！");
                //    }
                //}
                Application.Exit();
            }

        }

        private void btnpassword_Click(object sender, EventArgs e)
        {
            UserPassword password = new UserPassword(this);
            password.ShowDialog();
        }

        private void pcbsystemjournal_Click(object sender, EventArgs e)
        {
            SystemNode system = new SystemNode();
            system.ShowDialog();
        }



        private void MainForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            usersystemnode node = new usersystemnode();
            Model.usersystemnode nodeModel = new Model.usersystemnode();
            nodeModel.username = Operator;
            nodeModel.loginTime = logintime;
            nodeModel.leaveTime = DateTime.Now;
            node.Add(nodeModel);
            Application.Exit();

        }

        private void btnhelp_Click(object sender, EventArgs e)
        {
            try
            {
                System.Diagnostics.Process.Start(Application.StartupPath + @"\帮助文档(管理端).chm");
            }
            catch (Exception)
            {

                return;
            }

        }

        private void pcbsystemreset_Click(object sender, EventArgs e)
        {
            SystemInitialize system = new SystemInitialize();
            system.ShowDialog();
        }

        private void goodsflowing_Click(object sender, EventArgs e)
        {
            GoodsFlowing flow = new GoodsFlowing();
            flow.ShowDialog();

        }

        private void pcbforegrounding_Click(object sender, EventArgs e)
        {
            FrontSettingForm front = new FrontSettingForm(this);
            front.ShowDialog();
        }


        private void timer2_Tick(object sender, EventArgs e)
        {
            panel1.Top -= 20;
            if (panel1.Bottom <= 60)
            {
                timer2.Stop();
                dgvMemberInfo.Left = 8; dgvMemberInfo.Width = 1323;
            }
        }
        private void timer3_Tick(object sender, EventArgs e)
        {
            panel1.Top += 20;
            if (panel1.Top >= 60)
            {
                timer3.Stop();
            }
        }

        private void button1_MouseMove(object sender, MouseEventArgs e)
        {
            if (panel1.Bottom <= 60)
            {
                dgvMemberInfo.Left = 205;
                dgvMemberInfo.Width = 1126;
                timer3.Start();
            }
            if (panel1.Top >= 60)
            {
                timer2.Start();
            }
        }
        //int isopen = 0;
        public void Forread()
        {
            //string data = "";
            string blocknum = "1";
            //VN.WriteData(blocknum, data);
            //return;
            string mima;
            string data;
            try
            {
                string strReturn = vnp.RfidCardRequestAndReadNum();

                if (strReturn == "1")
                {
                    MessageBox.Show("机器内没有卡，请插卡");
                    return;
                }
                else
                {
                    //mima = vnp.ZSGW_KeyPass(strReturn);
                    mima = "FFFFFFFFFFFF";

                    data = vnp.RfidCardRequestAndReadData(blocknum, mima);
 
                }
            }
            catch (Exception)
            {

                MessageBox.Show("此卡不是本公司的卡片！请与本公司联系。电话：010-51291008");
                return;
            }

            this.txtCardByid.Text = data;
            if (txtCardByid.Text == "")
            {
                MessageBox.Show("没有找到卡中会员");
                return;
            }
            string xxbb = " memberCardId = '" + this.txtCardByid.Text + "'";

            memberInfo memberInfoBll = new memberInfo();
            DataTable dt = memberInfoBll.GetList(xxbb).Tables[0];
            dgvMemberInfo.DataSource = dt;
            Areas area = new Areas();
            ZG_member.Model.Areas areMode = new ZG_member.Model.Areas();
            foreach (DataGridViewRow dgvr in dgvMemberInfo.Rows)
            {
                if (dgvr.Cells["sexName"].Value != null)
                {
                    if (dgvr.Cells["sexName"].Value + "" == "女")
                    {
                        dgvr.Cells["sexName"].Value = "女";
                    }
                    else
                    {
                        dgvr.Cells["sexName"].Value = "男";
                    }
                }

                if (dgvr.Cells["AreasID"].Value != null)
                {
                    int id = int.Parse(dgvr.Cells["AreasID"].Value.ToString());
                    areMode = area.getModel(id);
                    dgvr.Cells["AreaName"].Value = areMode.AreaName;
                }
                if (dgvr.Cells["status1"].Value != null)
                {
                    if (dgvr.Cells["status1"].Value + "" == "正常")
                    {
                        dgvr.Cells["Newstatus"].Value = "正常";
                    }
                    if (dgvr.Cells["status1"].Value + "" == "挂失")
                    {
                        dgvr.Cells["Newstatus"].Value = "挂失";
                    }
                    if (dgvr.Cells["status1"].Value + "" == "停用")
                    {
                        dgvr.Cells["Newstatus"].Value = "停用";
                    }
                }
                consumeSolution consume = new consumeSolution();
                Model.consumeSolution consumeMod = new Model.consumeSolution();
                if (dgvr.Cells["cardType1"].Value != null)
                {
                    int ID = int.Parse(dgvr.Cells["cardType1"].Value.ToString());
                    consumeMod = consume.GetModelList("id='" + ID + "'")[0];
                    dgvr.Cells["NewcardType"].Value = consumeMod.solutionName;
                }
            }
        }
        //public void ExportExcel(string fileName, DataGridView myDGV)
        //{
        //    string saveFileName = "";
        //    //bool fileSaved = false;
        //    SaveFileDialog saveDialog = new SaveFileDialog();
        //    saveDialog.DefaultExt = "xls";
        //    saveDialog.Filter = "Excel文件|*.xls";
        //    saveDialog.FileName = fileName;
        //    saveDialog.ShowDialog();
        //    saveFileName = saveDialog.FileName;
        //    if (saveFileName.IndexOf(":") < 0) return; //被点了取消 
        //    Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();
        //    if (xlApp == null)
        //    {
        //        MessageBox.Show("无法创建Excel对象，可能您的机子未安装Office.Excel组件");
        //        return;
        //    }
        //    ZhengZaiDaoChu.max = Convert.ToInt32(deyeshu);
        //    ZhengZaiDaoChu daochu = new ZhengZaiDaoChu(1,this);
        //    daochu.Show();
        //    Microsoft.Office.Interop.Excel.Workbooks workbooks = xlApp.Workbooks;
        //    Microsoft.Office.Interop.Excel.Workbook workbook = workbooks.Add(Microsoft.Office.Interop.Excel.XlWBATemplate.xlWBATWorksheet);
        //    Microsoft.Office.Interop.Excel.Worksheet worksheet = (Microsoft.Office.Interop.Excel.Worksheet)workbook.Worksheets[1];//取得sheet1 
        //    int colIndex = 0;
        //    //写入标题
        //    for (int i = 0; i < myDGV.ColumnCount; i++)
        //    {
        //        if (myDGV.Columns[i].Visible)
        //        {
        //            colIndex++;
        //            worksheet.Cells[1, colIndex] = myDGV.Columns[i].HeaderText;
        //            //  worksheet.Cells[1, i] = myDGV.Columns[i].HeaderText;
        //        }
        //    }
        //    //写入数值
        //    int rowsCount = 0;
        //    for (int yeshu = 1; yeshu <= Convert.ToInt32(deyeshu); yeshu++)
        //    {
        //        try
        //        {

        //            daochu.progressBar1.Value++;
        //            memberInfo memInfo = new memberInfo();
        //            DataTable dt = memInfo.Mains(size, yeshu.ToString(), "").Tables[0];

        //            myDGV.DataSource = dt;
        //            consumeSolution consume = new consumeSolution();
        //            Model.consumeSolution consumeMod = new Model.consumeSolution();
        //            Areas area = new Areas();
        //            ZG_member.Model.Areas areMode = new ZG_member.Model.Areas();
        //            foreach (DataGridViewRow dgvr in myDGV.Rows)
        //            {


        //                if (dgvr.Cells["cardType1"].Value != null)
        //                {
        //                    int ID = int.Parse(dgvr.Cells["cardType1"].Value.ToString());
        //                    consumeMod = consume.GetModelList("id='" + ID + "'")[0];
        //                    dgvr.Cells["NewcardType"].Value = consumeMod.solutionName;
        //                }

        //                if (dgvr.Cells["AreasID"].Value != null)
        //                {
        //                    int id = int.Parse(dgvr.Cells["AreasID"].Value.ToString());
        //                    areMode = area.getModel(id);
        //                    dgvr.Cells["AreaName"].Value = areMode.AreaName;
        //                }

        //            }
        //        }
        //        catch (Exception ex)
        //        {
        //            MessageBox.Show(ex.ToString());
        //        }

        //    for (int r = 0; r < myDGV.Rows.Count; r++)
        //    {
        //        colIndex = 0;

        //        for (int i = 0; i < myDGV.ColumnCount; i++)
        //        {
        //            if (myDGV.Columns[i].Visible)
        //            {
        //                colIndex++;
        //                if (colIndex == 3)
        //                {
        //                    worksheet.Cells[rowsCount + 2, colIndex] ="'"+myDGV.Rows[r].Cells[i].Value;
        //                    continue;
        //                }
        //                if (colIndex == 6)
        //                {
        //                    worksheet.Cells[rowsCount + 2, colIndex] = "'" + myDGV.Rows[r].Cells[i].Value;
        //                    continue;
        //                }
        //                if (colIndex == 9)
        //                {
        //                    worksheet.Cells[rowsCount + 2, colIndex] = "'" + myDGV.Rows[r].Cells[i].Value;
        //                    continue;
        //                }
        //                worksheet.Cells[rowsCount + 2, colIndex] = myDGV.Rows[r].Cells[i].Value;
        //            }
        //        }
        //        rowsCount++;
        //        //System.Windows.Forms.Application.DoEvents();
        //    }
        //    }
        //    worksheet.Columns.EntireColumn.AutoFit();//列宽自适应

        //    if (saveFileName != "")
        //    {
        //        try
        //        {
        //            workbook.Saved = true;
        //            workbook.SaveCopyAs(saveFileName);
        //            //fileSaved = true;
        //        }
        //        catch (Exception ex)
        //        {
        //            //fileSaved = false;
        //            MessageBox.Show("导出文件时出错,文件可能正被打开！/n" + ex.Message);
        //        }

        //    }
        //    xlApp.Quit();
        //    GC.Collect();//强行销毁 
        //    // if (fileSaved && System.IO.File.Exists(saveFileName)) System.Diagnostics.Process.Start(saveFileName); //打开EXCEL

        //    MessageBox.Show("导出成功", "系统提示", MessageBoxButtons.OK);
        //    daochu.Close();
        //}
        //public void TransferData(string excelFile, string sheetName, string connectionString)
        //{
        //    ZhengZaiDaoChu daochu = new ZhengZaiDaoChu(0);

        //    //ZG_member.BLL.memberInfo adv = new ZG_member.BLL.memberInfo();
        //    //ZG_member.Model.memberInfo advMode = new ZG_member.Model.memberInfo();
        //    //DataTable advTB = adv.GetList("").Tables[0];

        //    DataSet ds = new DataSet();


        //    try
        //    {
        //        //获取全部数据   
        //        string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + excelFile + ";" + "Extended Properties=Excel 8.0;";
        //        OleDbConnection conn = new OleDbConnection(strConn);
        //        conn.Open();
        //        string strExcel = "";
        //        OleDbDataAdapter myCommand = null;
        //        strExcel = string.Format("select * from [{0}$]", sheetName);
        //        myCommand = new OleDbDataAdapter(strExcel, strConn);
        //        myCommand.Fill(ds, sheetName);
        //        bool bl = true;
        //        ZhengZaiDaoChu.max = ds.Tables[0].Rows.Count;
        //        //如果目标表不存在则创建   
        //        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
        //        {
        //            ZhengZaiDaoChu.max = ds.Tables[0].Rows.Count;
        //            daochu.Show();
        //            string strSql = "insert into memberInfo (AreasID,memberId,memberName,sex,mobile,createDate,expiresDate,Address,Email,tuiguangren,memo,cardType) values(";
        //            //strSql += string.Format("{0} varchar(255),", c.ColumnName);

        //            //if (advTB.Columns[i + 1].ToString() == ds.Tables[0].Columns[i].ToString())
        //            //{
        //            for (int j = 0; j < ds.Tables[0].Columns.Count; j++)
        //            {
        //                if (j == 0)
        //                {             
        //                    continue;
        //                }
        //                if (j == 1)
        //                {
        //                    Areas area=new Areas();
        //                    ZG_member.Model.Areas areaMode=new ZG_member.Model.Areas();
        //                    string AreasName = ds.Tables[0].Rows[i][j].ToString();
        //                    areaMode = area.getModelToString(AreasName);
        //                    strSql += areaMode.id + ",";
        //                    string diqu = ds.Tables[0].Rows[i][j].ToString();
        //                    areaMode= area.getModelToString(diqu);
        //                    memberInfo member=new memberInfo();
        //                    ZG_member.Model.memberInfo memberMode=new ZG_member.Model.memberInfo();
        //                    DataTable dt = member.GetListSql("select memberId from memberInfo where id in (select MAX(id)from memberInfo)").Tables[0];
        //                    string maxMemberId = dt.Rows[0][0].ToString();
        //                    maxMemberId= maxMemberId.Substring(8,maxMemberId.Length-8);

        //                    int memberid= Convert.ToInt32(maxMemberId);
        //                    maxMemberId=(memberid + 1).ToString();

        //                    List<string> list = new List<string>();
        //                    string Write = "";
        //                    for (int w = 0; w < maxMemberId.Length; w++)
        //                    {
        //                        list.Add(maxMemberId[w].ToString());
        //                    }
        //                    for (int s = 0; s < list.Count; s++)
        //                    {
        //                        if (list[s].ToString() == "4" || list[s].ToString() == "7")
        //                        {
        //                            list[s] = (Convert.ToInt32(list[s]) + 1).ToString();
        //                        }
        //                        Write += list[s];
        //                    }
        //                    maxMemberId = Write.PadLeft(8, '0');
        //                    string memberId = "8881" + areaMode.AreaNumber + maxMemberId;
        //                    ds.Tables[0].Rows[i][j] = memberId;
        //                }

        //                if (j == 3)
        //                {
        //                    string sex = ds.Tables[0].Rows[i][j].ToString();
        //                    if (sex == "男")
        //                    {
        //                        ds.Tables[0].Rows[i][j] = true;
        //                    }
        //                    else
        //                    {
        //                        ds.Tables[0].Rows[i][j] = false;
        //                    }
        //                }
        //                if (j == 5)
        //                {
        //                    strSql+="'"+DateTime.Now.ToString("yyyy-MM-dd")+"',";
        //                    continue;
        //                }
        //                if (j == 6)
        //                {
        //                    strSql+="'"+DateTime.Now.AddMonths(2).ToString("yyyy-MM-dd")+"',";
        //                    continue;
        //                }

        //                //if (j == ds.Tables[0].Rows.Count - 1)
        //                //{

        //                //    break;
        //                //}
        //                strSql += "'" + ds.Tables[0].Rows[i][j].ToString() + "',";

        //            }
        //            //}
        //            //else
        //            //{
        //            //    bl = false;
        //            //    if (bl == false)
        //            //    {
        //            //        MessageBox.Show("Excel与数据库标题不一致");
        //            //        return;
        //            //    }
        //            //    break;
        //            //}
        //            strSql += "19,";
        //            strSql = strSql.Trim(',') + ")";


        //            using (System.Data.SqlClient.SqlConnection sqlconn = new System.Data.SqlClient.SqlConnection(connectionString))
        //            {
        //                sqlconn.Open();
        //                System.Data.SqlClient.SqlCommand command = sqlconn.CreateCommand();
        //                command.CommandText = strSql;
        //                command.ExecuteNonQuery();
        //                sqlconn.Close();
        //                daochu.progressBar1.Value++;

        //            }

        //        }
        //        // 用bcp导入数据   
        //        //using (System.Data.SqlClient.SqlBulkCopy bcp = new System.Data.SqlClient.SqlBulkCopy(connectionString))
        //        //{
        //        //    bcp.SqlRowsCopied += new System.Data.SqlClient.SqlRowsCopiedEventHandler(bcp_SqlRowsCopied);
        //        //    bcp.BatchSize = 100;//每次传输的行数   
        //        //    bcp.NotifyAfter = 100;//进度提示的行数   
        //        //    bcp.DestinationTableName = "goods";//目标表   
        //        //    bcp.WriteToServer(ds.Tables[0]);
        //        //}
        //    }
        //    catch (Exception ex)
        //    {
        //        //System.Windows.Forms.MessageBox.Show(ex.Message);
        //        MessageBox.Show("请确保Excel格式内容正确!");
        //        return;
        //    }
        //    goods good = new goods();
        //    DataTable dtt = good.GetList("").Tables[0];
        //    MessageBox.Show("导入成功");


        //}

        public static string xianshi = "0";
        private void tvwMenu_AfterSelect(object sender, TreeViewEventArgs e)
        {
            string ids = "0";

            if (dgvMemberInfo.Rows.Count != 0)
            {
                if (dgvMemberInfo.CurrentRow.Cells["membercardId"].Value.ToString() != "")
                {
                    ids = dgvMemberInfo.CurrentRow.Cells["membercardId"].Value.ToString();
                }
            }

            string memberId = "0";

            if (dgvMemberInfo.Rows.Count != 0)
            {
                if (dgvMemberInfo.CurrentRow.Cells["memberId"].Value.ToString() != "")
                {
                    memberId = dgvMemberInfo.CurrentRow.Cells["memberId"].Value.ToString();
                }
            }
            //tvwMenu.SelectedNode = tvwMenu.Nodes[0];
            //if (xianshi == "1")
            //{
            //    if (tvwMenu.SelectedNode.Text != "会员消费")
            //    {
            //        if (tvwMenu.SelectedNode.Text == "会员管理中心")
            //        {
            //            return;
            //        }
            //        MessageBox.Show("由于未能连接服务器，次功能将无法使用！");
            //        tvwMenu.SelectedNode = tvwMenu.Nodes[0];
            //        return;
            //    }
            //}



            switch (tvwMenu.SelectedNode.Text)
            {

                //会员管理中心
                case "添加会员":
                    Down = true;

                    publishCardForm pcardAdd = new publishCardForm(this, "0", vnp);
                        pcardAdd.Text = "添加会员";
                        pcardAdd.ShowDialog();
                    


                    //int status = VN.StatusDemand();     
                    //if (status != 0x02)
                    //{
                    //    if (isopen == 0)
                    //    {
                    //        this.timer1.Start();
                    //        isopen = 1;
                    //    }
                    //    memberInfobindDataGridView();
                    //}
                    //else
                    //{

                    //}
                    break;
                case "折扣查询":
                    Discount dis = new Discount();
                    dis.ShowDialog();
                    break;
                case "短信设置":
                    duanxinshezhi duanxin = new duanxinshezhi();
                    duanxin.ShowDialog();
                    break;
                case "回信统计":
                    replystatistics duanxins = new replystatistics();
                    duanxins.ShowDialog();
                    break;
              
                case "批量会员导入":
                    ZhengZaiDaoChu daochu = new ZhengZaiDaoChu(0, this);
                    daochu.ShowDialog();
                    break;
                case "批量会员导出":

                    //ExportExcel("",dgvMemberInfo);
                    ZhengZaiDaoChu daochus = new ZhengZaiDaoChu(1, this);
                    daochus.ShowDialog();
                    break;
                case "修改会员":
                    try
                    {
                        if (ids != ""&&memberId!="")
                        {
                            publishCardForm pcard = new publishCardForm(this, ids, vnp);
                            pcard.Text = "会员卡信息修改";
                            pcard.ShowDialog();
                        }
                   
                    }
                    catch (Exception)
                    {

                        MessageBox.Show("请选择会员！");
                    }



                    break;
                case "会员充值":

                    RechargeForm charge = new RechargeForm(this, ids,memberId, vnp);
                    charge.Text = "会员充值";
                    charge.ShowDialog();
                    //int statuss = VN.StatusDemand();
                    //if (statuss != 0x02)
                    //{
                    //    if (isopen == 0)
                    //    {
                    //        this.timer1.Start();
                    //        isopen = 1;
                    //    }
                    //    memberInfobindDataGridView();
                    //}
                    //else
                    //{

                    //}
                    break;
                case "删除会员":
                    if (ids != "0")
                    {
                        Decimal balance = Decimal.Parse(dgvMemberInfo.CurrentRow.Cells["Balance"].Value.ToString());
                        int ID = int.Parse(dgvMemberInfo.CurrentRow.Cells["id"].Value.ToString());
                        if (dgvMemberInfo.CurrentRow.Cells["id"].Value != null)
                        {
                            DialogResult dr = MessageBox.Show("卡内余额为:" + balance + ",是否删除？", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
                            if (dr == DialogResult.OK)
                            {
                                memberInfo menber = new memberInfo();
                                ZG_member.Model.memberInfo menberMode = new ZG_member.Model.memberInfo();
                                ZG_member.BLL.SalesStaffList sales = new ZG_member.BLL.SalesStaffList();
                                ZG_member.Model.SalesStaffList salesMode = new ZG_member.Model.SalesStaffList();
                                ZG_member.BLL.SalesWasteBook salesWaste = new ZG_member.BLL.SalesWasteBook();
                                ZG_member.Model.SalesWasteBook salesWasteMode = new ZG_member.Model.SalesWasteBook();
                                ZG_member.BLL.wasteBook waste = new ZG_member.BLL.wasteBook();
                                ZG_member.Model.wasteBook wasteMode = new ZG_member.Model.wasteBook();
                                menberMode = menber.GetModel(ID);
                                //销售人员减钱
                                salesMode = sales.GetModel(menberMode.OpenTeacher);
                                if (salesMode == null)
                                {
                                    MessageBox.Show("请关联销售！");
                                    return;
                                }
                                salesMode.Money = Convert.ToDouble(balance * -1);
                                sales.Update(salesMode);
                                //销售流水添加记录
                                salesWasteMode.SalesPersonId = menberMode.OpenTeacher;
                                salesWasteMode.Dates = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd"));
                                salesWasteMode.Source = "充值";
                                salesWasteMode.money = Convert.ToDouble(balance * -1);
                                salesWasteMode.memberId = menberMode.memberId;
                                salesWaste.add(salesWasteMode);
                                //消费流水增加记录
                                wasteMode.memberCardId = menberMode.memberId;
                                wasteMode.consumeTimes = "1";
                                wasteMode.operatorId = MainForm.Operator;
                                wasteMode.consumeType = menberMode.cardType;
                                wasteMode.cardPayMoney = 0;
                                wasteMode.cashPayMoney = 0;
                                wasteMode.consumeMoney = balance * -1;
                                wasteMode.consumeIntegral = 0;
                                //wastebookModel.totalIntegral = int.Parse(this.txtjifenzhifu.Text) + (int)decimal.Parse(Integral);
                                wasteMode.totalIntegral = 0;
                                wasteMode.exchangeIntegral = 0;
                                wasteMode.savingMoney = balance * -1;
                                wasteMode.refundmentIntegral = 0;
                                wasteMode.refundmentMoney = balance;
                                //wastebookModel.cardBalance = decimal.Parse(this.TxtBalance.Text) + decimal.Parse(TxtCardPay.Text);
                                wasteMode.cardBalance = 0;
                                wasteMode.date = DateTime.Parse(DateTime.Now.ToString());
                                wasteMode.details = "退款记录";
                                wasteMode.terminalId = "0";
                                wasteMode.Discount = 0;
                                wasteMode.Jiedairen = "";
                                waste.Add(wasteMode);

                                if (menber.Delete(ID))
                                {


                                    MainForm_Load(sender, e);
                                }
                            }
                        }
                    }
                    break;
                case "挂失办理":
                    LoseCardForm lose = new LoseCardForm(this,ids, memberId, vnp);
                    lose.Text = "挂失办理";
                    lose.ShowDialog();
                    break;
                case "查找会员":
                    MenberSelect select = new MenberSelect(this);
                    select.Text = "查找会员";
                    select.ShowDialog();
                    break;
                case "统计区块":
                    StatisticsBlock block = new StatisticsBlock();
                    block.ShowDialog();
                    break;
                case "课程阶段":
                    CourseStage course = new CourseStage();
                    course.ShowDialog();
                    break;
                case "客户预约":
                    appointment ament = new appointment();
                    ament.ShowDialog();
                    break;
                case "讲话设置":
                    Speak spform = new Speak();
                    spform.ShowDialog();
                    
                    break;
                case "添加用户":

                    publishCardForm userAdd = new publishCardForm(this, vnp, memberId);
                    userAdd.Text = "添加用户";
                    userAdd.ShowDialog();
                    break;
                case "修改卡密码":
                    changepassword change = new changepassword();
                    if (dgvMemberInfo.Rows.Count > 0)
                    {
                        change.txtCardId.Text = dgvMemberInfo.CurrentRow.Cells["memberId"].Value.ToString();
                        change.txtmemberName.Text = dgvMemberInfo.CurrentRow.Cells["memberName"].Value.ToString();
                    }
                    else
                    {
                        MessageBox.Show("请选择要修改卡密码的会员");
                    }
                    change.Text = "修改卡密码";
                    change.ShowDialog();
                    break;
                case "角色管理":
                    RollInfo info = new RollInfo();
                    info.Text = "角色管理";
                    info.ShowDialog();
                    break;
                case "生日提醒设置":
                    birthdayFrom bf = new birthdayFrom();
                    bf.Text = "生日提醒设置";
                    bf.ShowDialog();
                    break;
                case "卡面设计":
                    CardTemplateDesignMainForm cardTemp = new CardTemplateDesignMainForm();
                    cardTemp.Text = "卡面设计";
                    cardTemp.ShowDialog();
                    break;
                case "商品流水":
                    GoodsFlowing flow = new GoodsFlowing();
                    flow.Text = "商品流水";
                    flow.ShowDialog();

                    break;

                //基本设置


                case "销售管理":
                    SalesStaffList salesp = new SalesStaffList();
                    salesp.ShowDialog();
                    break;

                case "施工管理":
                    Worker worker = new Worker();
                    worker.ShowDialog();
                    break;



                case "会员等级":
                    ConsumeSolutionForm solutionForm = new ConsumeSolutionForm();
                    solutionForm.Text = "会员等级";
                    solutionForm.ShowDialog();
                    bindClbxMemberLevel();
                    break;
                case "商品设置":
                    ProduceForm Form = new ProduceForm(this);
                    Form.Text = "商品设置";
                    Form.ShowDialog();

                    break;
                case "群发短信":
                    SendMsgsForm smf = new SendMsgsForm();
                    smf.Text = "群发短信";
                    smf.ShowDialog();
                    break;

                case "群发邮件":
                    List<string> asd = new List<string>();
                    email emal = new email(asd, 1);
                    emal.Text = "商品设置";
                    emal.ShowDialog();

                    break;


                //会员行为记录
                case "会员行为记录":
                    MemberRecord record = new MemberRecord();
                    record.ShowDialog();
                    break;
                //到期查询
                case "到期查询":
                    ExpireQuery expire = new ExpireQuery();
                    expire.ShowDialog();
                    break;

                //系统设置
                case "系统日志":
                    SystemNode system = new SystemNode();
                    system.Text = "系统日志";
                    system.ShowDialog();
                    break;
                case "操作员管理":
                    OperatorInfo info1 = new OperatorInfo();
                    info1.Text = "操作员管理";
                    info1.ShowDialog();
                    break;
                case "备份恢复":
                    ReStoreForm Form1 = new ReStoreForm();
                    Form1.Text = "备份恢复";
                    Form1.ShowDialog();
                    break;
                case "前台设置":
                    FrontSettingForm front = new FrontSettingForm(this);
                    front.Text = "前台设置";
                    front.ShowDialog();
                    break;
                case "系统初始化":
                    SystemInitialize system1 = new SystemInitialize();
                    system1.Text = "系统初始化";
                    system1.ShowDialog();
                    break;
                //卡片设置
                case "进卡":
                    int aa = vnp.CardInOver();
                    if (aa == 0)
                    {
                        MessageBox.Show("端口打开失败~！");
                    }
                    else if (aa == 1)
                    {
                        MessageBox.Show("进卡失败~！");
                    }
                    //if (statusss != 0x02)
                    //{
                    //    if (isopen == 0)
                    //    {
                    //        this.timer1.Start();
                    //        isopen = 1;
                    //    }
                    //    memberInfobindDataGridView();
                    //}
                    //else
                    //{

                    //}
                    break;
                case "出卡":
                    int chuka = vnp.Dischange();
                    if (chuka == 0)
                    {
                        MessageBox.Show("端口打开失败~！");
                    }
                    else if (chuka == 1)
                    {
                        MessageBox.Show("进卡失败~！");
                    }
                    //int statussss = VN.StatusDemand();
                    //if (statussss != 0x02)
                    //{
                    //    if (isopen == 0)
                    //    {
                    //        this.timer1.Start();
                    //        isopen = 1;
                    //    }
                    //    memberInfobindDataGridView();
                    //}
                    //else
                    //{

                    //}
                    break;
                case "弹卡":
                    //VN.TanCard();

                    break;
                case "清洗机器":
                    //VN.CleanPrinter();

                    break;
                case "删除卡面内容":
                    vnp.ErasePrintDischarge2();


                    break;
                //case "读卡":
                //        //读卡
                //        string content = "";

                //        vp.ReadData(1,ref content);
                //        MessageBox.Show(content);
                //        tvwMenu.SelectedNode = tvwMenu.Nodes[0];
                //        break;
                case "客户查询":
                    CustomerChart cc = new CustomerChart();
                    cc.Text = "客户查询";
                    cc.ShowDialog();
                    break;
                case "用户贡献查询":
                    CustomerContributeChart cust = new CustomerContributeChart();
                    cust.Text = "用户贡献查询";
                    cust.ShowDialog();
                    break;
                case "充值查询":
                    RechargeMoneyChart money = new RechargeMoneyChart();
                    money.Text = "充值查询";
                    money.ShowDialog();

                    break;
                case "商品查询":
                    GoodsChart cg = new GoodsChart();
                    cg.Text = "商品查询";
                    cg.ShowDialog();
                    break;
                //前台业务
                case "会员消费":

                    if (dgvMemberInfo.CurrentRow.Cells["membercardId"].Value != "" || dgvMemberInfo.CurrentRow.Cells["memberId"].Value != "")
                    {

                        MemberSaleForm memberSaleForm = new MemberSaleForm(this,ids,memberId, vnp);
                        //MemberSaleForm.Order = 0;
                        //MemberSaleForm.wasteBookID = "";
                        memberSaleForm.ShowDialog();
                        //int statusssss = VN.StatusDemand();
                        //if (statusssss != 0x02)
                        //{
                        //    if (isopen == 0)
                        //    {
                        //        this.timer1.Start();
                        //        isopen = 1;
                        //    } 
                        //    memberInfobindDataGridView();
                        //}
                        //else
                        //{

                        //}
                    }



                    break;
                case "添加礼品":
                    GiftSetForm giftSet = new GiftSetForm("0");
                    giftSet.ShowDialog();

                    break;
                case "礼品设置":
                    installgift installgift = new installgift();
                    installgift.ShowDialog();
                    break;
                case "积分换礼":
                    IntegrationExchangeForm integration = new IntegrationExchangeForm(this,memberId, vnp);
                    integration.ShowDialog();
                    //int statussssss = VN.StatusDemand();
                    //if (statussssss != 0x02)
                    //{
                    //    if (isopen == 0)
                    //    {
                    //        this.timer1.Start();
                    //        isopen = 1;
                    //    }
                    //    memberInfobindDataGridView();
                    //}
                    //else
                    //{

                    //}
                    break;
                case "卡密码修改":
                    changepassword changePassword = new changepassword();
                    changePassword.ShowDialog();
                    break;
                case "更换用户":
                    LoginForm lf = new LoginForm('a', this);
                    lf.ShowDialog();
                    if (LoginForm.shuaxing)
                    {
                        UserInfo();
                    }

                    break;
                case "系统锁屏":
                    this.Visible = false;
                    LoginForm F1 = new LoginForm(1, this);
                    F1.ShowDialog();
                    if (LoginForm.shuaxing)
                    {
                        UserInfo();
                        this.Visible = true;
                    }
                    else
                    {
                        Application.Exit();
                        break;
                    }


                    break;

                //系统提醒
                case "卡金提醒":
                    BalanceRemindForm balanceRemmind = new BalanceRemindForm(this);
                    balanceRemmind.ShowDialog();
                    break;
                case "商品饼图查询":
                    GoodsChart_two good = new GoodsChart_two();
                    good.ShowDialog();
                    break;
                case "年龄分析":
                    AgeanalyseChart age = new AgeanalyseChart();
                    age.ShowDialog();
                    break;
                case "智能决策管理":
                    Intelligencerole il = new Intelligencerole();
                    il.Owner = this;
                    il.Show();
                    break;



                case "会员统计":
                    MembercartTypeChart mt = new MembercartTypeChart();
                    mt.ShowDialog();
                    break;
                case "生日提醒":
                    brithdayFromBill b = new brithdayFromBill();
                    b.ShowDialog();
                    break;

                //统计报表
                case "消费流水":
                    //ConsumptionBill cpBill = new ConsumptionBill(this);
                    //cpBill.ShowDialog();
                    //break;

                case "收入明细查询":
                    //InComeFormBill inComes = new InComeFormBill(this);
                    //inComes.ShowDialog();
                    //break;
                       ConsumptionBill cpBill = new ConsumptionBill(this);
                    cpBill.ShowDialog();
                    break;

                //case "会员储值记录":
                //        SavingMoneyFormBill savingMoney = new SavingMoneyFormBill(this);
                //        savingMoney.ShowDialog();
                //        break;
                case "礼品兑换统计":
                    GiftExBill gifExBill = new GiftExBill(this);
                    gifExBill.ShowDialog();
                    break;
                //case "出卡":
                //        VN.EjectCard();
                //        if (status != 0x02)
                //        {
                //            clearContent();
                //        }
                //        break;
                //case "删除卡片内容":
                //        VN.CleanCard();
                //        if (status != 0x02)
                //        {
                //            clearContent();
                //        }
                //        break;
                //case "清洗机器":
                //        VN.RCPCleaningAuto();
                //        break;

            }
            //int statussssssss = VN.StatusDemand();
            //if (statussssssss != 0x02)
            //{
            //    if (isopen == 0)
            //    {
            //        this.timer1.Start();
            //        isopen = 1;
            //    }

            //}
            //else
            //{
            //    if (isopen ==1)
            //    {
            //        this.timer1.Stop();
            //        isopen = 0;
            //    }

            //}
            //int status = VN.selectReadNum();

            //if (status != 0)
            //{
            //    this.timer1.Start();
            //}


            tvwMenu.SelectedNode = tvwMenu.Nodes[0];
        }




        private void clbxMemberLevel_SelectedValueChanged(object sender, EventArgs e)
        {
            BLL.operatorInfo oif = new BLL.operatorInfo();
            string where = " username = '" + MainForm.Operator + "' ";
            Model.operatorInfo omodle = oif.GetModelList(where)[0];
            //if (omodle.roleId != 13)
            //{
            //    MessageBox.Show("由于您不是最高管理员，你无法查看！");
            //    return;
            //}
            //GetcardType();
            CurrYes();
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            UserPassword password = new UserPassword(this);
            password.ShowDialog();
        }

        private void dgvMemberInfo_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            string ids = "0";
            if (dgvMemberInfo.CurrentRow.Cells["id"].Value != null)
            {
                ids = dgvMemberInfo.CurrentRow.Cells["id"].Value.ToString();
            }
            publishCardForm pcard = new publishCardForm(this, ids, vnp);
            if (dgvMemberInfo.CurrentRow.Cells["memberId"].Value != null)
            {
                pcard.txtMenberId.Text = dgvMemberInfo.CurrentRow.Cells["memberId"].Value.ToString();
            }

            if (dgvMemberInfo.CurrentRow.Cells["memberName"].Value != null)
            {
                pcard.txtMenberName.Text = dgvMemberInfo.CurrentRow.Cells["memberName"].Value.ToString();
            }
            if (dgvMemberInfo.CurrentRow.Cells["sexName"].Value != null)
            {
                pcard.cbxsex.Text = dgvMemberInfo.CurrentRow.Cells["sexName"].Value.ToString();
            }
            if (dgvMemberInfo.CurrentRow.Cells["Email"].Value != null)
            {
                pcard.txtEmail.Text = dgvMemberInfo.CurrentRow.Cells["Email"].Value.ToString();
            }
            if (dgvMemberInfo.CurrentRow.Cells["mobile1"].Value != null)
            {
                pcard.txtMobile.Text = dgvMemberInfo.CurrentRow.Cells["mobile1"].Value.ToString();
            }
            if (dgvMemberInfo.CurrentRow.Cells["Tel"].Value != null)
            {
                pcard.txtTel.Text = dgvMemberInfo.CurrentRow.Cells["Tel"].Value.ToString();
            }
            if (dgvMemberInfo.CurrentRow.Cells["Birthday"].Value != null)
            {
                pcard.dateBirthday.Text = dgvMemberInfo.CurrentRow.Cells["Birthday"].Value.ToString();
            }
            if (dgvMemberInfo.CurrentRow.Cells["IDNumber"].Value != null)
            {
                pcard.txtIDNumber.Text = dgvMemberInfo.CurrentRow.Cells["IDNumber"].Value.ToString();
            }
            if (dgvMemberInfo.CurrentRow.Cells["NewcardType"].Value != null)
            {
                pcard.cmbType.Text = dgvMemberInfo.CurrentRow.Cells["NewcardType"].Value.ToString();
            }
            if (dgvMemberInfo.CurrentRow.Cells["point"].Value != null)
            {
                pcard.txtPoint.Text = dgvMemberInfo.CurrentRow.Cells["point"].Value.ToString();
            }
            if (dgvMemberInfo.CurrentRow.Cells["Newstatus"].Value != null)
            {
                pcard.cbxStatus.Text = dgvMemberInfo.CurrentRow.Cells["Newstatus"].Value.ToString();
            }
            if (dgvMemberInfo.CurrentRow.Cells["CreateDate1"].Value != null)
            {
                pcard.dateCreateDate.Text = dgvMemberInfo.CurrentRow.Cells["CreateDate1"].Value.ToString();
            }
            if (dgvMemberInfo.CurrentRow.Cells["ExpiresDate"].Value != null)
            {
                pcard.dateExpiresDate.Text = dgvMemberInfo.CurrentRow.Cells["ExpiresDate"].Value.ToString();
            }


            if (dgvMemberInfo.CurrentRow.Cells["Memo"].Value != null)
            {
                pcard.txtMemo.Text = dgvMemberInfo.CurrentRow.Cells["Memo"].Value.ToString();
            }
            pcard.ShowDialog();
        }

        private void dgvMemberInfo_CellMouseDoubleClick_1(object sender, DataGridViewCellMouseEventArgs e)
        {
            Down = false;
            string ids = "0";
            if (dgvMemberInfo.CurrentRow.Cells["membercardId"].Value != null && dgvMemberInfo.CurrentRow.Cells["membercardId"].Value != "")
            {
                ids = dgvMemberInfo.CurrentRow.Cells["membercardId"].Value.ToString();
            }
            string memberId = "0";
            if (dgvMemberInfo.CurrentRow.Cells["memberId"].Value != null && dgvMemberInfo.CurrentRow.Cells["memberId"].Value != "")
            {
                memberId = dgvMemberInfo.CurrentRow.Cells["memberId"].Value.ToString();
            }
            publishCardForm.UpdateId = Convert.ToInt32(this.dgvMemberInfo.CurrentRow.Cells["id"].Value);
            publishCardForm pcard;
            if (ids != "0")
            {
                 pcard = new publishCardForm(this, ids, vnp);
            }
            else
            {
                 pcard = new publishCardForm(this, vnp, memberId);
            }
            pcard.Text = "会员卡信息修改";
            pcard.ShowDialog();
        }

        private void dgvMemberInfo_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            consumeSolution consume = new consumeSolution();
            Model.consumeSolution consumeMod = new Model.consumeSolution();
            Areas area = new Areas();
            ZG_member.Model.Areas areMode = new ZG_member.Model.Areas();
            foreach (DataGridViewRow dgvr in dgvMemberInfo.Rows)
            {


                if (dgvr.Cells["cardType1"].Value != null)
                {
                    int ID = int.Parse(dgvr.Cells["cardType1"].Value.ToString());
                    consumeMod = consume.GetModelList("id='" + ID + "'")[0];
                    dgvr.Cells["NewcardType"].Value = consumeMod.solutionName;
                }
                if (dgvr.Cells["AreasID"].Value != null)
                {
                    int id = int.Parse(dgvr.Cells["AreasID"].Value.ToString());
                    areMode = area.getModel(id);
                    dgvr.Cells["AreaName"].Value = areMode.AreaName;
                }
            }
        }

        private void timer4_Tick(object sender, EventArgs e)
        {
            this.Opacity += 0.02;
            if (this.Opacity == 1)
            {
                this.timer4.Stop();
                //this.timer1.Start();
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {

        }
        public static string GetNumber(string str)
        {
            string result = "0";
            if (str != null && str != string.Empty)
            {

                // 正则表达式剔除非数字字符（不包含小数点.）
                str = Regex.Replace(str, @"[^\d.\d]", "");
                // 如果是数字，则转换为decimal类型
                if (Regex.IsMatch(str, @"^[+-]?\d*[.]?\d*$"))
                {
                    result = str.ToString();
                }
            }
            return result;
        }
        int flag = 0;
        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (flag == 0)
            {
                e.Cancel = true;
                flag = 1;
                DialogResult dr = MessageBox.Show("是否备份数据库？", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
                if (dr == DialogResult.OK)
                {
                    string beifen = ConfigurationManager.AppSettings["BackDataBase"];
                    string beifenName = ConfigurationManager.AppSettings["BackDataBaseName"];
                    SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
                    SqlCommand cmdBK = new SqlCommand(@"backup database " + beifenName + " to disk='" + beifen + "_" + GetNumber(DateTime.Now.ToString()) + ".bak' with init", conn);
                    cmdBK.CommandType = CommandType.Text;


                    try
                    {
                        conn.Open();
                        cmdBK.ExecuteNonQuery();
                        MessageBox.Show("备份成功");
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString());
                    }

                    finally
                    {
                        conn.Close();

                        conn.Dispose();
                        this.Close();
                    }
                }
                this.Close();
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            string sst = NewYe();
            dgvMemberInfo.Columns["Balance"].DefaultCellStyle.Format = "N2";
            dgvMemberInfo.Columns["consume"].DefaultCellStyle.Format = "N2";
            try
            {

                string st = (Convert.ToInt32(num) + 1).ToString();
                memberInfo memInfo = new memberInfo();
                DataTable dt = memInfo.Mains(size, st, sst, "").Tables[0];
                consumeSolution consume = new consumeSolution();
                Model.consumeSolution consumeMod = new Model.consumeSolution();
                Areas area = new Areas();
                ZG_member.Model.Areas areMode = new ZG_member.Model.Areas();
                string[] list = new string[] { };
                taocanjiluBLL taocan = new taocanjiluBLL();
                Model.taocanjilu taocanMode = new Model.taocanjilu();
                if (dt.Rows.Count != 0)
                {
                    num = (Convert.ToInt32(num) + 1).ToString();
                    this.txtCurr.Text = num;

                    dgvMemberInfo.DataSource = dt;

                    foreach (DataGridViewRow dgvr in dgvMemberInfo.Rows)
                    {
                        string cardType1 = dgvr.Cells["cardType1"].Value.ToString();
                        if (cardType1 != "")
                        {
                            int ID = int.Parse(dgvr.Cells["cardType1"].Value.ToString());
                            consumeMod = consume.GetModelList("id='" + ID + "'")[0];
                            dgvr.Cells["NewcardType"].Value = consumeMod.solutionName;
                        }
                        if (dgvr.Cells["AreasID"].Value != "")
                        {
                            int id = int.Parse(dgvr.Cells["AreasID"].Value.ToString());
                            areMode = area.getModel(id);
                            dgvr.Cells["AreaName"].Value = areMode.AreaName;
                        }

                    }
                }
                else
                {
                    MessageBox.Show("已是最后一页");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (this.txtCurr.Text == "1")
            {
                MessageBox.Show("本页已是首页！");
                return;
            }
            string sst = NewYe();
            string shaixuan = shaixuantiaoj();
            dgvMemberInfo.Columns["Balance"].DefaultCellStyle.Format = "N2";
            dgvMemberInfo.Columns["consume"].DefaultCellStyle.Format = "N2";
            try
            {
                num = "1";
                this.txtCurr.Text = num;
                memberInfo memInfo = new memberInfo();
                DataTable dt;
                if (this.txtjiedairen.Text.Trim() != "")
                {
                    dt = memInfo.Mains(size, num, sst, shaixuan).Tables[0];
                }
                else
                {
                    dt = memInfo.Mains(size, num, sst, "").Tables[0];
                }
                Areas area = new Areas();
                ZG_member.Model.Areas areMode = new ZG_member.Model.Areas();
                string[] list = new string[] { };
                taocanjiluBLL taocan = new taocanjiluBLL();
                Model.taocanjilu taocanMode = new Model.taocanjilu();
                BLL.consumeSolution consume = new BLL.consumeSolution();
                Model.consumeSolution consumeMod = new Model.consumeSolution();
                dgvMemberInfo.DataSource = dt;
                CurrYe();

                foreach (DataGridViewRow dgvr in dgvMemberInfo.Rows)
                {
                    string cardType1 = dgvr.Cells["cardType1"].Value.ToString();
                    if (cardType1 != "")
                    {
                        int ID = int.Parse(dgvr.Cells["cardType1"].Value.ToString());
                        consumeMod = consume.GetModelList("id='" + ID + "'")[0];
                        dgvr.Cells["NewcardType"].Value = consumeMod.solutionName;
                    }
                    if (dgvr.Cells["AreasID"].Value != "")
                    {
                        int id = int.Parse(dgvr.Cells["AreasID"].Value.ToString());
                        areMode = area.getModel(id);
                        dgvr.Cells["AreaName"].Value = areMode.AreaName;
                    }
                    if (dgvr.Cells["Shengyukecheng"].Value != "")
                    {
                        string memberId = dgvr.Cells["memberId"].Value.ToString();
                        taocanMode = taocan.GetModelFormemberCardId(memberId);
                        int shengyukecheng = 0;
                        if (taocanMode == null)
                        {
                            dgvr.Cells["Shengyukecheng"].Value = 0;
                            continue;
                        }
                        if (taocanMode.Xiangqing != null)
                        {
                            list = taocanMode.Xiangqing.Split('|');
                            for (int i = 0; i < list.Count() - 1; i++)
                            {
                                shengyukecheng = shengyukecheng + Convert.ToInt32(list[i].Substring(list[i].IndexOf(',') + 1));
                            }
                            dgvr.Cells["Shengyukecheng"].Value = shengyukecheng;
                        }
                        else
                        {
                            dgvr.Cells["Shengyukecheng"].Value = 0;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        public string shaixuantiaoj()
        {
            string shaixuan = "";
            if (this.txtjiedairen.Text.Trim() != "")
            {
                shaixuan = "createDate >= '" + this.dtpqishi.Value + "' and createDate <= '" + this.dtpjiezhi.Value + "' and tuiguangren = '" + this.txtjiedairen.Text + "' ";

            }
            return shaixuan;
        }
        private void button3_Click(object sender, EventArgs e)
        {
            string sst = NewYe();
            string shaixuan = shaixuantiaoj();
            if (Convert.ToInt32(num) > 1)
            {
                dgvMemberInfo.Columns["Balance"].DefaultCellStyle.Format = "N2";
                dgvMemberInfo.Columns["consume"].DefaultCellStyle.Format = "N2";
                num = (Convert.ToInt32(num) - 1).ToString();
                this.txtCurr.Text = num;
                memberInfo memInfo = new memberInfo();
                DataTable dt;
                if (this.txtjiedairen.Text.Trim() != "")
                {
                    dt = memInfo.Mains(size, num, sst, shaixuan).Tables[0];
                }
                else
                {
                    dt = memInfo.Mains(size, num, sst, "").Tables[0];
                }



                dgvMemberInfo.DataSource = dt;
                consumeSolution consume = new consumeSolution();
                Model.consumeSolution consumeMod = new Model.consumeSolution();
                Areas area = new Areas();
                ZG_member.Model.Areas areMode = new ZG_member.Model.Areas();
                string[] list = new string[] { };
                taocanjiluBLL taocan = new taocanjiluBLL();
                Model.taocanjilu taocanMode = new Model.taocanjilu();
                foreach (DataGridViewRow dgvr in dgvMemberInfo.Rows)
                {

                    string cardType1 = dgvr.Cells["cardType1"].Value.ToString();
                    if (cardType1 != "")
                    {
                        int ID = int.Parse(dgvr.Cells["cardType1"].Value.ToString());
                        consumeMod = consume.GetModelList("id='" + ID + "'")[0];
                        dgvr.Cells["NewcardType"].Value = consumeMod.solutionName;
                    }
                    if (dgvr.Cells["AreasID"].Value != "")
                    {
                        int id = int.Parse(dgvr.Cells["AreasID"].Value.ToString());
                        areMode = area.getModel(id);
                        dgvr.Cells["AreaName"].Value = areMode.AreaName;
                    }
                    if (dgvr.Cells["Shengyukecheng"].Value != "")
                    {
                        string memberId = dgvr.Cells["memberId"].Value.ToString();
                        taocanMode = taocan.GetModelFormemberCardId(memberId);
                        int shengyukecheng = 0;
                        if (taocanMode == null)
                        {
                            dgvr.Cells["Shengyukecheng"].Value = 0;
                            continue;
                        }
                        if (taocanMode.Xiangqing != null)
                        {
                            list = taocanMode.Xiangqing.Split('|');
                            for (int i = 0; i < list.Count() - 1; i++)
                            {
                                shengyukecheng = shengyukecheng + Convert.ToInt32(list[i].Substring(list[i].IndexOf(',') + 1));
                            }
                            dgvr.Cells["Shengyukecheng"].Value = shengyukecheng;
                        }
                        else
                        {
                            dgvr.Cells["Shengyukecheng"].Value = 0;
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("已是首页");
            }
        }

        private void button5_Click(object sender, EventArgs e)
        {
            if (this.txtAlto.Text == "1")
            {
                MessageBox.Show("本页已是末页！");
                return;
            }
            CurrYe();
            string sst = NewYe();
            string shaixuan = shaixuantiaoj();
            dgvMemberInfo.Columns["Balance"].DefaultCellStyle.Format = "N2";
            dgvMemberInfo.Columns["consume"].DefaultCellStyle.Format = "N2";
            try
            {
                num = deyeshu;
                this.txtCurr.Text = num;
                memberInfo memInfo = new memberInfo();
                DataTable dt;
                if (this.txtjiedairen.Text.Trim() != "")
                {
                    dt = memInfo.Mains(size, num, sst, shaixuan).Tables[0];
                }
                else
                {
                    dt = memInfo.Mains(size, num, sst, "").Tables[0];
                }

                dgvMemberInfo.DataSource = dt;
                Areas area = new Areas();
                ZG_member.Model.Areas areMode = new ZG_member.Model.Areas();
                string[] list = new string[] { };
                taocanjiluBLL taocan = new taocanjiluBLL();
                Model.taocanjilu taocanMode = new Model.taocanjilu();
                BLL.consumeSolution consume = new BLL.consumeSolution();
                Model.consumeSolution consumeMod = new Model.consumeSolution();
                foreach (DataGridViewRow dgvr in dgvMemberInfo.Rows)
                {

                    string cardType1 = dgvr.Cells["cardType1"].Value.ToString();
                    if (cardType1 != "")
                    {
                        int ID = int.Parse(dgvr.Cells["cardType1"].Value.ToString());
                        consumeMod = consume.GetModelList("id='" + ID + "'")[0];
                        dgvr.Cells["NewcardType"].Value = consumeMod.solutionName;
                    }
                    if (dgvr.Cells["AreasID"].Value != "")
                    {
                        int id = int.Parse(dgvr.Cells["AreasID"].Value.ToString());
                        areMode = area.getModel(id);
                        dgvr.Cells["AreaName"].Value = areMode.AreaName;
                    }
                    if (dgvr.Cells["Shengyukecheng"].Value != "")
                    {
                        string memberId = dgvr.Cells["memberId"].Value.ToString();
                        taocanMode = taocan.GetModelFormemberCardId(memberId);
                        int shengyukecheng = 0;
                        if (taocanMode == null)
                        {
                            dgvr.Cells["Shengyukecheng"].Value = 0;
                            continue;
                        }
                        if (taocanMode.Xiangqing != null)
                        {
                            list = taocanMode.Xiangqing.Split('|');
                            for (int i = 0; i < list.Count() - 1; i++)
                            {
                                shengyukecheng = shengyukecheng + Convert.ToInt32(list[i].Substring(list[i].IndexOf(',') + 1));
                            }
                            dgvr.Cells["Shengyukecheng"].Value = shengyukecheng;
                        }
                        else
                        {
                            dgvr.Cells["Shengyukecheng"].Value = 0;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

        private void button6_Click(object sender, EventArgs e)
        {
            if (this.textBox1.Text == txtCurr.Text)
            {
                return;
            }
            string yeshu = this.textBox1.Text;
            string sst = NewYe();
            string shaixuan = shaixuantiaoj();
            dgvMemberInfo.Columns["Balance"].DefaultCellStyle.Format = "N2";
            dgvMemberInfo.Columns["consume"].DefaultCellStyle.Format = "N2";
            try
            {
                memberInfo memInfo = new memberInfo();
                DataTable dt;
                if (this.txtjiedairen.Text.Trim() != "")
                {
                    dt = memInfo.Mains(size, num, sst, shaixuan).Tables[0];
                }
                else
                {
                    dt = memInfo.Mains(size, num, sst, "").Tables[0];
                }
                Areas area = new Areas();
                ZG_member.Model.Areas areMode = new ZG_member.Model.Areas();
                consumeSolution consume = new consumeSolution();
                Model.consumeSolution consumeMod = new Model.consumeSolution();
                string[] list = new string[] { };
                taocanjiluBLL taocan = new taocanjiluBLL();
                Model.taocanjilu taocanMode = new Model.taocanjilu();
                if (dt.Rows.Count != 0)
                {
                    num = yeshu;
                    this.txtCurr.Text = yeshu;

                    dgvMemberInfo.DataSource = dt;

                    foreach (DataGridViewRow dgvr in dgvMemberInfo.Rows)
                    {
                        string cardType1 = dgvr.Cells["cardType1"].Value.ToString();
                        if (cardType1 != "")
                        {
                            int ID = int.Parse(dgvr.Cells["cardType1"].Value.ToString());
                            consumeMod = consume.GetModelList("id='" + ID + "'")[0];
                            dgvr.Cells["NewcardType"].Value = consumeMod.solutionName;
                        }
                        if (dgvr.Cells["AreasID"].Value != "")
                        {
                            int id = int.Parse(dgvr.Cells["AreasID"].Value.ToString());
                            areMode = area.getModel(id);
                            dgvr.Cells["AreaName"].Value = areMode.AreaName;
                        }
                        if (dgvr.Cells["Shengyukecheng"].Value != "")
                        {
                            string memberId = dgvr.Cells["memberId"].Value.ToString();
                            taocanMode = taocan.GetModelFormemberCardId(memberId);
                            int shengyukecheng = 0;
                            if (taocanMode == null)
                            {
                                dgvr.Cells["Shengyukecheng"].Value = 0;
                                continue;
                            }
                            if (taocanMode.Xiangqing != null)
                            {
                                list = taocanMode.Xiangqing.Split('|');
                                for (int i = 0; i < list.Count() - 1; i++)
                                {
                                    shengyukecheng = shengyukecheng + Convert.ToInt32(list[i].Substring(list[i].IndexOf(',') + 1));
                                }
                                dgvr.Cells["Shengyukecheng"].Value = shengyukecheng;
                            }
                            else
                            {
                                dgvr.Cells["Shengyukecheng"].Value = 0;
                            }
                        }
                    }
                }
                else
                {
                    MessageBox.Show("已超过最大页数");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

        }

        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!(((e.KeyChar >= '0') && (e.KeyChar <= '9')) || e.KeyChar <= 31))
            {
                //if (e.KeyChar == '.')
                //{
                //    if (((TextBox)sender).Text.Trim().IndexOf('.') > -1)
                //        e.Handled = true;
                //}
                //else
                e.Handled = true;
            }
            else
            {
                if (e.KeyChar <= 31)
                {
                    e.Handled = false;
                }
                else if (((TextBox)sender).Text.Trim().IndexOf('.') > -1)
                {
                    if (((TextBox)sender).Text.Trim().Substring(((TextBox)sender).Text.Trim().IndexOf('.') + 1).Length >= 4)
                        e.Handled = true;
                }
            }
        }

        //private void timer1_Tick_1(object sender, EventArgs e)
        //{
        //    int status = VN.selectReadNum();

        //    if (status == 0)
        //    {
        //        Forread();
        //        this.timer1.Stop();
        //    }
        //    //else
        //    //{

        //    //    //this.timer1.Stop();
        //    //    //isopen = 0;
        //    //}

        //}

        private void 会员消费ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string ids = "0";
            string memberId = "0";
            if (dgvMemberInfo.Rows.Count != 0)
            {
                if (dgvMemberInfo.CurrentRow.Cells["membercardId"].Value != null && dgvMemberInfo.CurrentRow.Cells["membercardId"].Value != "")
                {
                    ids = dgvMemberInfo.CurrentRow.Cells["membercardId"].Value.ToString();
                }
            }

            if (dgvMemberInfo.CurrentRow.Cells["memberId"].Value != null && dgvMemberInfo.CurrentRow.Cells["memberId"].Value!="")
            {
                memberId = dgvMemberInfo.CurrentRow.Cells["memberId"].Value.ToString();
            }


            if (ids != "0" || memberId != "0")
            {
                MemberSaleForm sa=new MemberSaleForm(this,ids,memberId,vnp);
                sa.ShowDialog();
            }
            else
            {
                MessageBox.Show("请选择会员");
            }
            

        }

        private void 会员充值ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string ids = "0";
            string memberId = "0";
            if (dgvMemberInfo.Rows.Count != 0)
            {
                if (dgvMemberInfo.CurrentRow.Cells["membercardId"].Value != null)
                {
                    ids = dgvMemberInfo.CurrentRow.Cells["membercardId"].Value.ToString();
                }
            }
            if (dgvMemberInfo.Rows.Count != 0)
            {
                if (dgvMemberInfo.CurrentRow.Cells["memberId"].Value != null)
                {
                    memberId = dgvMemberInfo.CurrentRow.Cells["memberId"].Value.ToString();
                }
            }
            if (ids != "0")
            {
                LoseCardForm lc = new LoseCardForm(this, ids, memberId, vnp);
                lc.Text = "挂失办理";
                lc.ShowDialog();
                //RechargeForm charge = new RechargeForm(this, ids, VN);
                //charge.Text = "会员充值";
                //charge.ShowDialog();
                //int statuss = VN.StatusDemand();
                //if (statuss != 0x02)
                //{
                //    if (isopen == 0)
                //    {
                //        this.timer1.Start();
                //        isopen = 1;
                //    }
                shifouxianshi(MainForm.Operator);
                //}
                //else
                //{

                //}
            }
            else
            {
                MessageBox.Show("列表为空，无法修改");
            }

        }

        private void 积分换礼ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string ids = "0";
            string memberIds="0";
            if (dgvMemberInfo.Rows.Count != 0)
            {
                if (dgvMemberInfo.CurrentRow.Cells["membercardId"].Value != null)
                {
                    ids = dgvMemberInfo.CurrentRow.Cells["membercardId"].Value.ToString();
                }
            }
            if (dgvMemberInfo.Rows.Count != 0)
            {
                if (dgvMemberInfo.CurrentRow.Cells["memberIds"].Value != null)
                {
                    memberIds = dgvMemberInfo.CurrentRow.Cells["memberIds"].Value.ToString();
                }
            }
            if (ids != "0")
            {
                IntegrationExchangeForm integration = new IntegrationExchangeForm(this,memberIds,vnp);
                integration.ShowDialog();
                //int statussssss = VN.StatusDemand();
                //if (statussssss != 0x02)
                //{
                //    if (isopen == 0)
                //    {
                //        this.timer1.Start();
                //        isopen = 1;
                //    }
                shifouxianshi(MainForm.Operator);
                //}
                //else
                //{

                //}
            }
            else
            {
                MessageBox.Show("列表为空，无法修改");
            }

        }

        private void 修改会员ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Down = false;
            string ids = "0";
            string memberId = "0";
            
            if (dgvMemberInfo.CurrentRow.Cells["membercardId"].Value != null)
            {
                ids = dgvMemberInfo.CurrentRow.Cells["membercardId"].Value.ToString();
            }
            if (dgvMemberInfo.CurrentRow.Cells["memberId"].Value != null)
            {
                memberId = dgvMemberInfo.CurrentRow.Cells["memberId"].Value.ToString();
            }
            if (ids != "0")
            {
                publishCardForm pcard = new publishCardForm(this, ids, vnp);
                pcard.ShowDialog();
            }
            else if(memberId!="0")
            {
                publishCardForm pcard = new publishCardForm(this, vnp, memberId);
                pcard.ShowDialog();
            }
            
        }

        private void 删除会员ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string ids = "0";

            if (dgvMemberInfo.Rows.Count != 0)
            {
                if (dgvMemberInfo.CurrentRow.Cells["memberId"].Value != null)
                {
                    ids = dgvMemberInfo.CurrentRow.Cells["memberId"].Value.ToString();
                }
            }
            if (ids != "0")
            {
                Decimal balance = Decimal.Parse(dgvMemberInfo.CurrentRow.Cells["Balance"].Value.ToString());
                int ID = int.Parse(dgvMemberInfo.CurrentRow.Cells["id"].Value.ToString());
                if (dgvMemberInfo.CurrentRow.Cells["id"].Value != null)
                {
                    if (balance > 0)
                    {
                        MessageBox.Show("卡内余额不为零,不能删除!");
                    }
                    else
                    {

                        //DialogResult dr = MessageBox.Show("您确定要删除该条信息吗？","温馨提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);

                        //if (dr == DialogResult.OK)
                        //{
                        if (DialogResult.OK == MessageBox.Show("确定删除？", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information))
                        {
                            memberInfo menber = new memberInfo();
                            wasteBook w = new wasteBook();
                            if (menber.Delete(ID))
                            {
                                try
                                {
                                    w.DeleteListbyCardid(ids);
                                }
                                catch (Exception)
                                {


                                }

                                shifouxianshi(MainForm.Operator);
                            }
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("列表为空，无法删除！");
            }
        }

        private void button7_Click(object sender, EventArgs e)
        {
            Forread();
        }
        ZG_member.SendMsgsForm smmf = new ZG_member.SendMsgsForm();
        private void timer5_Tick(object sender, EventArgs e)
        {
            try
            {
                HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://sdk2.entinfo.cn:8060/webservice.asmx");
                HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
                if (resp.StatusCode == HttpStatusCode.OK)
                {
                    resp.Close();
                    smmf.shouxin();
                }
                else
                {

                }
            }
            catch (WebException webex)
            {
                //this.timer5.Stop();
                //MessageBox.Show("由于您的计算机未连网！将无法接受短信！");

            }

        }

        private void dgvMemberInfo_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                if (e.RowIndex >= 0)
                {
                    dgvMemberInfo.ClearSelection();
                    dgvMemberInfo.Rows[e.RowIndex].Selected = true;
                    dgvMemberInfo.CurrentCell = dgvMemberInfo.Rows[e.RowIndex].Cells[e.ColumnIndex];

                }
            }

        }

        public void shaixuan()
        {
            StringBuilder sb = new StringBuilder();
            string sign = "";
            for (int i = 0; i < clbxMemberLevel.Items.Count; i++)
            {
                if (clbxMemberLevel.GetItemChecked(i))
                {
                    sb.Append(sign);
                    sb.Append("'");
                    sb.Append(clbxMemberLevel.Items[i].ToString());
                    sb.Append("'");
                    sign = ",";
                }
            }
            if (sb.ToString() == "")
            {
                sb.Append("null");
            }
            string abc = sb.ToString();
            string sst = "";
            if (SelectMemberTJ.Trim() != "")
            {
                sst = "" + SelectMemberTJ + " and cardType in (select id from consumeSolution where solutionName in (" + sb.ToString() + "))order by id ";
            }
            else
            {
                sst = "cardType in (select id from consumeSolution where solutionName in (" + sb.ToString() + "))order by id";
            }
            string shaixuan = "";
            if (this.txtjiedairen.Text.Trim() != "")
            {
                shaixuan = "createDate >= '" + this.dtpqishi.Value + "' and createDate <= '" + this.dtpjiezhi.Value + "' and tuiguangren = '" + this.txtjiedairen.Text + "' ";
                memberInfobindDataGridView(sst, shaixuan);
            }


        }

        public void Order(string memberId)
        {
            if (dgvMemberInfo.Rows.Count == 0)
            {
                MessageBox.Show("列表为空，无法查看消费详情！");
                return;
            }
            BLL.wasteBook wb = new wasteBook();
            tabControl1.SelectedIndex = 1;

            try
            {
                string where = " memberCardId = '" + memberId + "'";
                DataTable ds = wb.GetList(where).Tables[0];
                consumeSolution consume = new consumeSolution();
                Model.consumeSolution consumeMode = new Model.consumeSolution();
                this.DgvConsumptionBill.DataSource = ds;
                try
                {
                    for (int i = 0; i < DgvConsumptionBill.Rows.Count; i++)
                    {
                        consumeMode = consume.GetModel(Convert.ToInt32(DgvConsumptionBill.Rows[i].Cells["ConsumeType"].Value));
                        DgvConsumptionBill.Rows[i].Cells["CardType"].Value = consumeMode.solutionName;


                        if (DgvConsumptionBill.Rows[i].Cells["Checkout_bukejian"].Value.ToString() == "1")
                        {
                            DgvConsumptionBill.Rows[i].Cells["Checkout"].Value = true;
                        }
                        else
                        {
                            DgvConsumptionBill.Rows[i].Cells["Checkout"].Value = false;
                        }
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("没有此等级");

                }

                //DgvConsumptionBill.AllowUserToAddRows = false;
                //consumeSolution consume = new consumeSolution();
                //Model.consumeSolution consumeMod = new Model.consumeSolution();
                //if (DgvConsumptionBill.Rows.Count > 0)
                //{
                //    for (int i = 0; i < DgvConsumptionBill.Rows.Count; i++)
                //    {
                //        if (DgvConsumptionBill.Rows[i].Cells["ConsumeType"].Value.ToString() != "")
                //        {
                //            consumeMod = consume.GetModel(int.Parse(DgvConsumptionBill.Rows[i].Cells["ConsumeType"].Value.ToString()));
                //            DgvConsumptionBill.Rows[i].Cells["CardType"].Value = consumeMod.solutionName;
                //        }
                //        if (DgvConsumptionBill.Rows[i].Cells["Discount"].Value.ToString() != "")
                //        {
                //            DgvConsumptionBill.Rows[i].Cells["DiscountNew"].Value = DgvConsumptionBill.Rows[i].Cells["Discount"].Value + "%";
                //        }
                //    }
                //}

            }
            catch (Exception)
            {

                MessageBox.Show("暂无消费流水！");
            }

        }


        private void button8_Click(object sender, EventArgs e)
        {

            if (this.txtjiedairen.Text.Trim() == "")
            {
                shifouxianshi(MainForm.Operator);
            }
            BLL.operatorInfo oif = new BLL.operatorInfo();
            string where = " username = '" + MainForm.Operator + "' ";
            Model.operatorInfo omodle = oif.GetModelList(where)[0];
            if (omodle.roleId != 13)
            {
                MessageBox.Show("由于您不是最高管理员，你无法查看！");
                return;
            }
            shaixuan();
        }

        public void 消费流水ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (dgvMemberInfo.Rows.Count == 0)
            {
                MessageBox.Show("列表为空，无法查看消费详情！");
                return;
            }
            BLL.wasteBook wb = new wasteBook();
            tabControl1.SelectedIndex = 1;
            if (dgvMemberInfo.CurrentRow.Cells["memberId"].Value.ToString().Trim() != "")
            {
                try
                {
                    string where = " memberCardId = '" + dgvMemberInfo.CurrentRow.Cells["memberId"].Value.ToString().Trim() + "' order by id desc";
                    DataSet ds = wb.GetList(where);
                    consumeSolution consume = new consumeSolution();
                    Model.consumeSolution consumeMode = new Model.consumeSolution();
                    DataTable dt = ds.Tables[0];
                    double kafujine = 0;
                    double xianjinzhifu = 0;
                    double xiaofeijine = 0;
                    double chongzhijine = 0;
                    double tuikuanjine = 0;
                    double kaneiyue = 0;
                    DataRow row1;
                    row1 = dt.NewRow();
                    row1[2] = "结算";
                    dt.Rows.Add(row1);
                    this.DgvConsumptionBill.DataSource = dt;
                    try
                    {
                        for (int i = 0; i < this.DgvConsumptionBill.Rows.Count-1; i++)
                        {
                            consumeMode = consume.GetModel(Convert.ToInt32(DgvConsumptionBill.Rows[i].Cells["ConsumeType"].Value));
                            DgvConsumptionBill.Rows[i].Cells["CardType"].Value = consumeMode.solutionName;


                            //if (DgvConsumptionBill.Rows[i].Cells["Checkout_bukejian"].Value.ToString() == "1")
                            //{
                            //    DgvConsumptionBill.Rows[i].Cells["Checkout"].Value = true;
                            //}
                            //else
                            //{
                            //    DgvConsumptionBill.Rows[i].Cells["Checkout"].Value = false;
                            //}
                            kafujine += Convert.ToDouble(DgvConsumptionBill.Rows[i].Cells["Column8"].Value);
                            xianjinzhifu += Convert.ToDouble(DgvConsumptionBill.Rows[i].Cells["Column9"].Value);
                            xiaofeijine += Convert.ToDouble(DgvConsumptionBill.Rows[i].Cells["Column7"].Value);
                            chongzhijine += Convert.ToDouble(DgvConsumptionBill.Rows[i].Cells["Column15"].Value);
                            tuikuanjine += Convert.ToDouble(DgvConsumptionBill.Rows[i].Cells["Column11"].Value);
                            kaneiyue+= Convert.ToDouble(DgvConsumptionBill.Rows[i].Cells["Column10"].Value);
                        }
                        this.DgvConsumptionBill.Rows[DgvConsumptionBill.Rows.Count - 1].Cells["Column8"].Value = kafujine;
                        this.DgvConsumptionBill.Rows[DgvConsumptionBill.Rows.Count - 1].Cells["Column9"].Value = xianjinzhifu;
                        this.DgvConsumptionBill.Rows[DgvConsumptionBill.Rows.Count - 1].Cells["Column7"].Value = xiaofeijine;
                        this.DgvConsumptionBill.Rows[DgvConsumptionBill.Rows.Count - 1].Cells["Column15"].Value = chongzhijine;
                        this.DgvConsumptionBill.Rows[DgvConsumptionBill.Rows.Count - 1].Cells["Column11"].Value = tuikuanjine;
                        this.DgvConsumptionBill.Rows[DgvConsumptionBill.Rows.Count - 1].Cells["Column10"].Value = kaneiyue;
                      

                    }
                    catch (Exception)
                    {
                        MessageBox.Show("没有此等级");

                    }

                    //DgvConsumptionBill.AllowUserToAddRows = false;
                    //consumeSolution consume = new consumeSolution();
                    //Model.consumeSolution consumeMod = new Model.consumeSolution();
                    //if (DgvConsumptionBill.Rows.Count > 0)
                    //{
                    //    for (int i = 0; i < DgvConsumptionBill.Rows.Count; i++)
                    //    {
                    //        if (DgvConsumptionBill.Rows[i].Cells["ConsumeType"].Value.ToString() != "")
                    //        {
                    //            consumeMod = consume.GetModel(int.Parse(DgvConsumptionBill.Rows[i].Cells["ConsumeType"].Value.ToString()));
                    //            DgvConsumptionBill.Rows[i].Cells["CardType"].Value = consumeMod.solutionName;
                    //        }
                    //        if (DgvConsumptionBill.Rows[i].Cells["Discount"].Value.ToString() != "")
                    //        {
                    //            DgvConsumptionBill.Rows[i].Cells["DiscountNew"].Value = DgvConsumptionBill.Rows[i].Cells["Discount"].Value + "%";
                    //        }
                    //    }
                    //}

                }
                catch (Exception)
                {

                    MessageBox.Show("暂无消费流水！");
                }
            }
        }
        public void xianshixiangqing()
        {
            tabControl1.SelectedIndex = 2;
            goodsInfo goods = new goodsInfo();
            ZG_member.Model.goodsInfo goodsModel = new ZG_member.Model.goodsInfo();
            DataTable dt = goods.GetListWhere("").Tables[0];
            goods gd = new goods();
            ZG_member.Model.goods goodsMode = new ZG_member.Model.goods();
            dgvxiaofeixiangqing.DataSource = dt;
            if (dgvxiaofeixiangqing.Rows.Count != 0)
            {
                //foreach (DataGridViewRow item in dgvxiaofeixiangqing.Rows)
                //{
                //    if (item.Cells["gid"].Value.ToString() != "")
                //    {
                //        goodsMode = gd.getModelGoodsIdString(item.Cells["gid"].Value.ToString());

                //        item.Cells["gidNew"].Value = goodsMode.goodsName;
                //        MessageBox.Show("DGV:" + item.Cells["gidNew"].Value + "，goodname：" + goodsMode.goodsName);

                //    }
                //}
                for (int i = 0; i < dgvxiaofeixiangqing.Rows.Count; i++)
                {
                    goodsMode = gd.getModelGoodsIdString(dgvxiaofeixiangqing.Rows[i].Cells["gid"].Value.ToString());
                    dgvxiaofeixiangqing.Rows[i].Cells["gidNew"].Value = goodsMode.goodsName;
                }

                //;
            }
        }
        private void 消费详情ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (DgvConsumptionBill.Rows.Count == 0)
            {
                MessageBox.Show("列表为空，无法查看消费详情！");
                return;
            }
            tabControl1.SelectedIndex = 2;
            string ID = DgvConsumptionBill.CurrentRow.Cells["Column1"].Value.ToString();
            goodsInfo goods = new goodsInfo();
            ZG_member.Model.goodsInfo goodsModel = new ZG_member.Model.goodsInfo();
            DataTable dt = goods.GetListWhere(" wasteBookId='" + ID + "'").Tables[0];
            goods gd = new goods();
            ZG_member.Model.goods goodsMode = new ZG_member.Model.goods();
            dgvxiaofeixiangqing.DataSource = dt;
            if (dgvxiaofeixiangqing.Rows.Count != 0)
            {
                //foreach (DataGridViewRow item in dgvxiaofeixiangqing.Rows)
                //{
                //    if (item.Cells["gid"].Value.ToString() != "")
                //    {
                //        goodsMode = gd.getModelGoodsIdString(item.Cells["gid"].Value.ToString());

                //        item.Cells["gidNew"].Value = goodsMode.goodsName;
                //        MessageBox.Show("DGV:" + item.Cells["gidNew"].Value + "，goodname：" + goodsMode.goodsName);

                //    }
                //}
                for (int i = 0; i < dgvxiaofeixiangqing.Rows.Count; i++)
                {
                    try
                    {
                        goodsMode = gd.getModelGoodsIdString(dgvxiaofeixiangqing.Rows[i].Cells["gid"].Value.ToString());

                        dgvxiaofeixiangqing.Rows[i].Cells["gidNew"].Value = goodsMode.goodsName;
                    }
                    catch (Exception)
                    {

                        continue;
                    }

                }

            }
            //dgvxiaofeixiangqing.Rows[0].Cells["gidNew"].Value = "123";

            //tabControl1.SelectedIndex = 2;
        }

        private void 返回上一页ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            tabControl1.SelectedIndex = 0;
        }

        private void 返回上一页ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            //this.dgvxiaofeixiangqing.DataSource = null;
            tabControl1.SelectedIndex = 1;
        }

        private void DgvConsumptionBill_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                if (e.RowIndex >= 0)
                {
                    DgvConsumptionBill.ClearSelection();
                    DgvConsumptionBill.Rows[e.RowIndex].Selected = true;
                    DgvConsumptionBill.CurrentCell = DgvConsumptionBill.Rows[e.RowIndex].Cells[e.ColumnIndex];

                }
            }
        }

        private void dgvxiaofeixiangqing_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                if (e.RowIndex >= 0)
                {
                    dgvMemberInfo.ClearSelection();
                    dgvMemberInfo.Rows[e.RowIndex].Selected = true;
                    dgvMemberInfo.CurrentCell = dgvMemberInfo.Rows[e.RowIndex].Cells[e.ColumnIndex];

                }
            }
        }

        private void 服务套餐ToolStripMenuItem_Click(object sender, EventArgs e)
        {


            string id = dgvMemberInfo.CurrentRow.Cells["membercardId"].Value.ToString().Trim();
            string memberid = dgvMemberInfo.CurrentRow.Cells["memberId"].Value.ToString().Trim();
            TaoCanfangan add = new TaoCanfangan(id,memberid, vnp, this);
            add.ShowDialog();

        }

        private void button9_Click(object sender, EventArgs e)
        {
            ExpiredInquiry ex = new ExpiredInquiry();
            ex.ShowDialog();
        }

        private void dgvMemberInfo_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void 消费结算ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //try
            //{
            //    if (this.DgvConsumptionBill.CurrentRow.Cells["Column1"].Value.ToString() != "")
            //    {
            //        wasteBook waste = new wasteBook();
            //        ZG_member.Model.wasteBook wasteMode = new ZG_member.Model.wasteBook();
            //        string Id = this.DgvConsumptionBill.CurrentRow.Cells["Column1"].Value.ToString();
            //        string memberId = this.DgvConsumptionBill.CurrentRow.Cells["Column4"].Value.ToString();
            //        memberInfo member = new memberInfo();
            //        ZG_member.Model.memberInfo memberMode = new ZG_member.Model.memberInfo();
            //        memberMode = member.GetModels(memberId);
            //        wasteMode = waste.GetModel(Convert.ToInt32(Id));
            //        if (wasteMode.cardPayMoney>0)
            //        {
            //            memberMode.Balance = memberMode.Balance + wasteMode.cardPayMoney;
            //            ZG_member.BLL.SalesStaffList sale = new ZG_member.BLL.SalesStaffList();
            //            ZG_member.Model.SalesStaffList saleMode = new ZG_member.Model.SalesStaffList();
            //            saleMode = sale.GetModel(memberMode.OpenTeacher);
            //            saleMode.
            //        }
            //        else
            //        {
 
            //        }
            //    }
            //}
            //catch (Exception)
            //{

            //    return;
            //}
         
        }

        private void 请假申请ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.dgvMemberInfo.Rows.Count > 0)
            {
                if (this.dgvMemberInfo.CurrentRow.Cells["memberId"].Value.ToString() != "")
                {
                    string memberId = this.dgvMemberInfo.CurrentRow.Cells["memberId"].Value.ToString();
                    LeaveAdd leave = new LeaveAdd(memberId);
                    leave.ShowDialog();
                }
            }
        }


        //private void 消费结算ToolStripMenuItem_Click(object sender, EventArgs e)
        //{
        //    MemberSaleForm.Order = 1;
        //    MemberSaleForm sale = new MemberSaleForm(this, dgvMemberInfo.CurrentRow.Cells["memberId"].Value.ToString(), vnp);
        //    MemberSaleForm.wasteBookID = DgvConsumptionBill.CurrentRow.Cells["Column1"].Value.ToString();
        //    if (DgvConsumptionBill.CurrentRow.Cells["Checkout"].Value.ToString() == "True")
        //    {
        //        sale.button1.Enabled = false;
        //        sale.button3.Enabled = false;
        //        sale.TxtPwd.Enabled = false;
        //        sale.cboGoods.Enabled = false;
        //        sale.numericUpDown1.Enabled = false;
        //        sale.button2.Enabled = false;
        //        sale.CbxPrintInfo.Enabled = false;
        //        sale.checkBox1.Enabled = false;
        //        sale.TxtOthers.Enabled = false;
        //        sale.txtjiedairen.Enabled = false;
        //        sale.button4.Enabled = false;
        //        sale.btnAccount.Enabled = false;
        //    }
        //    sale.ShowDialog();
        //}
































































    }
}
